BethShaffer Posted November 6, 2019 Report Share Posted November 6, 2019 Good morning, My search page has a header that displays information on how to use the page. When the search returns no results, that information is not needed and I want to display a different message on what they can do next. I know there is a place in my Style for a "no results found" message, but this does not remove the unneeded information in my header, it just displays new text below it and it makes the page too long. I need the code for displaying two different messages in the header of my page; one when search results are returned, and another when they are null. I know the basic if statement when it's for fields, but I don't know the correct syntax when it's for search results. Help is appreciated. Quote Link to comment Share on other sites More sharing options...
BethShaffer Posted November 6, 2019 Author Report Share Posted November 6, 2019 Here is my attempt, which of course, does not work. <script type="text/javascript"> if (document.getElementById("norecord")) { document.getElementById("message").innerHTML = "ONE MESSAGE"; } else { document.getElementById("message").innerHTML = "DIFFERENT MESSAGE"; } </script> Quote Link to comment Share on other sites More sharing options...
BethShaffer Posted November 6, 2019 Author Report Share Posted November 6, 2019 I've also tried giving the <div> an ID and then replacing its contents if there are no search results. <script type="text/javascript"> if (document.getElementById("norecord")) { document.getElementById("HOW").innerHTML = "Message to be Displayed if No Search Results"; } </script> <div id="HOW">Normal Message Displayed on the Page</div> Quote Link to comment Share on other sites More sharing options...
BethShaffer Posted November 6, 2019 Author Report Share Posted November 6, 2019 Ha! I got this working. I missed the step of having to name the ID for the No Results Message in Localizations. If someone else needs to change the header message when no results are found, this is how. I found some clues using this online help page, https://howto.caspio.com/integration/map-mashup/hiding-the-map-when-no-results-are-found/ Go to Localizations and choose the language you're using, and go to #351 No Records Found. Add a custom message if there isn't already one, and put a div tag around it with an ID, mine is "norecord" for this example. Then add another div tag around the header content you want to change and also give it an ID, ID="HOW" for this example. Then add this code to the footer of your Configure Results Page Fields: Match whatever names you give the respective fields to the IDs in the code below. <script type="text/javascript"> if (document.getElementById("norecord")) { document.getElementById("HOW").innerHTML = "THE NEW CONTENT YOU WANT DISPLAYED WHEN THERE ARE NO RECORDS"; } </script> This new content will overwrite whatever content is in the <div> named HOW when the search returns no results. If you're adding HTML to the new content, you need to escape all your quotes or it won't work. I made that mistake. In a link example, it would be: <a href=\"http://mywebsite.com\">Visit my website!</a> Leon13 and kpcollier 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.