user2144097 user2144097 - 5 months ago 8
Javascript Question

How to add "enter to search" option?

I would like to add that when I press "enter" in the search form, it will search, and not only when I click search button:

jQuery(document).ready(function(){
jQuery('#webq_search_submit').click(function() {
//code
});
jQuery('#webq_txt_search').click(function(){

jQuery('#webq_txt_search').css("border", "none");
});
});

Answer
jQuery('#webq_txt_search').on('keypress',function(e){

   if (e.keyCode === 13){
        console.log('enter detected');
   }
   // jQuery('#webq_txt_search').css("border", "none");
}));

Use if using this search inside form

$("form").submit(function() { return false; });

Comments