javascript - Search enable on press of enter -


i have search textbox has restrictions should not allow special characters, on click of enter key should redirect search page respective search. have added code regex not allowing special characters, how should achieve should redirect proper search page on click of enter when user types search.

my result search page name search.aspx. please see js code reference.

$(document).ready(function (){     $('#ctl00_topnavigation_txtsearch').bind('keypress', function (event) {         var regex = new regexp("^[a-za-z0-9\b _ _%]+$");         var key = string.fromcharcode(!event.charcode ? event.which : event.charcode);         if (!regex.test(key)) {             event.preventdefault();             return false;         }     }); }); 

try in keypress event

var searchurl = "search.aspx?tx=" + ctl00_topnavigation_txtsearch.val();  window.location.replace(searchurl); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -