none
Custom Search for a Custom Masterpage isn't passing querystring help please RRS feed

  • Question

  • I'm stuck, I can not figure out why the querystring isn't picking up the Search parameter.
    here is the code it is a .js in the style library. it will connect the results page but  the parameter k is empty.
     I have tried this with a reference to  google  jquery link and with out. it will go the results page but the querystring item is blank in the url

    masterpage code:

    <div class="search-container">

    <input id="search-input"  type="text" placeholder="Search..." onclick="this.value=''">

    <i id="search-submit" class="material-icons">search</i>

    </div>

    JS File:

    $(document).ready(function() {
              function inputSearch() {
                     var link = "";

                     $('#search-submit').click(function(event) {

                               event.preventDefault();

                               var queryString = $('#search-input').val();

                               // Make sure this location matches your site structure

                               var location = "/<site>/SitePages/results.aspx?u=#k=" + queryString;

                               link = location;

                               $('#search-input').attr("value", '');

                               window.location.href = link;

                               return;

                     });

              }

              inputSearch(); 

              $('#search-input').keypress(function(key) {

                     if($(this).is(":focus") && (key.which == 13)) {

                               $('#search-submit').click();

                     }

              });

        });




    • Edited by cowboy2066 Friday, January 13, 2017 6:41 PM
    Friday, January 13, 2017 4:46 PM

Answers

  • Hi,

    The following code for your reference:

    HTML code:

    <div class="search-container">
    	<input id="search-input"  type="text" placeholder="Search..." onclick="this.value=''"/>
    	<i id="search-submit" class="material-icons">search</i>
    </div>
    

    jQuery code:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {	
    	$('#search-submit').click(function(event) {	 
    		var queryString = $('#search-input').val();
    		// Make sure this location matches your site structure
    		var location = "/<site>/SitePages/results.aspx?u=#k=" + queryString;
    		window.location.href = location;	
    	});
    	
    	$('#search-input').keypress(function(key) {
    		if($(this).is(":focus") && (key.which == 13)) {		
    			$('#search-submit').click();
    		}
    	});
    
    });
    </script>

    Add the jQuery code into the <head/> tag in master page.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by cowboy2066 Tuesday, January 17, 2017 8:46 PM
    Monday, January 16, 2017 5:55 AM
    Moderator

All replies

  • Hi,

    The following code for your reference:

    HTML code:

    <div class="search-container">
    	<input id="search-input"  type="text" placeholder="Search..." onclick="this.value=''"/>
    	<i id="search-submit" class="material-icons">search</i>
    </div>
    

    jQuery code:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () {	
    	$('#search-submit').click(function(event) {	 
    		var queryString = $('#search-input').val();
    		// Make sure this location matches your site structure
    		var location = "/<site>/SitePages/results.aspx?u=#k=" + queryString;
    		window.location.href = location;	
    	});
    	
    	$('#search-input').keypress(function(key) {
    		if($(this).is(":focus") && (key.which == 13)) {		
    			$('#search-submit').click();
    		}
    	});
    
    });
    </script>

    Add the jQuery code into the <head/> tag in master page.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by cowboy2066 Tuesday, January 17, 2017 8:46 PM
    Monday, January 16, 2017 5:55 AM
    Moderator
  • it isn't doing anything now, it isn't even going to the results page.  just flashes and stays on the  page.

    long story short I finally got it to work. how I got it to work is placed it where the  Commented out Search box info was located at.

    but overall , I think people in future if they use this solution will have easier time.




    • Edited by cowboy2066 Tuesday, January 17, 2017 8:46 PM
    Tuesday, January 17, 2017 3:56 PM