Friday 2 October 2015

Javascript to redirect page to search page with passing query string

Leave a Comment
This is a example method in javascript to redirect page searching page plus carry whatever value type in the textbox after press enter button or click submit button.

Requirement

  • JQuery library

HTML


  <div class="input-group search-btn">  
       <input id="textSearch" type="text" onkeypress="keypressSearch(e);" class="form-control">  
       <span class="input-group-btn">  
        <button class="btn btn-default" onclick="return Search();return false;" type="button">SEARCH</button>  
       </span>  
      </div>  



Javascript


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>  
  <script type="text/javascript">   
    function Search() {   
     var txtField = jQuery("#textSearch").val();   
     document.location.href = "/Search.aspx?searchtext=" + txtField + "&searchmode=anyword";   
     return false;   
    }   
    function keypressSearch(event) {   
     if (event.keyCode == 13) {   
      Search();   
      return false;   
     }   
     else {   
     }   
    }     
   </script>    



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)

0 comments:

Post a Comment

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.