I have a content search web part that is optional to use. If a user finds an item through the filtered navigation I don't want them to see the content search web part. If they use the search box I want the web part to show the appropriate search results. I can get the web part to get the correct results from the correct source, but now it defaults to showing the items. Is there a way I can make the default show no items and then still run the correct search when a value is used in the search box?

1 Answer 1


One option that comes to my mind is using jQuery. On page load check if the search box has any values, based on that Show/Hide the results. Something like

    var searchValue = jQuery('#searchboxid').val();
    if(searchValue == null || searchValue == '' || searchValue == 'Search...') {

You can find the searchboxid and webpartid using browser developer tools.


Handling key events in Search Box

    var code = e.which;
    if(code==32||code==13||code==188||code==186) {
        //If required you can check if the box is empty
        //Handle backspace etc.
  • Tried this, there isn't a refresh or page navigation when you search for a term so the web part stays hidden.
    – Jordan
    Commented Nov 25, 2014 at 19:52
  • @Jordan in that case on page load you should hide the webpart using jQuery and then hook an onchange event handler on the search box and then show it. Commented Nov 25, 2014 at 19:56
  • I put an onchange event on my '#searchboxid' and it doesn't trigger my function when I search.
    – Jordan
    Commented Nov 25, 2014 at 20:09
  • @Jordan I have updated my answer. I tried it on my dev site and its working as expected. You should change the #id Commented Nov 25, 2014 at 20:13
  • This does work. Is there a way to change it on submit that you know of? Somehow to check when the .val() changes but obviously not an onchange handler as that didn't work.
    – Jordan
    Commented Nov 25, 2014 at 20:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.