Jump to content
BethShaffer

Different Header Information When Search Returns No Results

Recommended Posts

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.

 

 

Share this post


Link to post
Share on other sites

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>

 

Share this post


Link to post
Share on other sites

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>

 

Share this post


Link to post
Share on other sites

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/

  1. Go to Localizations and choose the language you're using, and go to #351 No Records Found.
  2. 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.
  3. Then add another div tag around the header content you want to change and also give it an ID, ID="HOW" for this example.
  4. Then add this code to the footer of your Configure Results Page Fields:
  5. 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>

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...