how to use $ function on two events simultaniously in jquery -


i have text box , image button, want search content entered in text box (both enter on text box) , click on search image(icon) should work..

i tried :

$(document).ready(function () {       $('.customsearchbutton').on("click","img", function (e) {         var search = $("#txtsearch").val();                 var searchencoded = encodeuricomponent(search);         window.location = "/search.aspx?name=" + searchencoded;       }); }); 

my html :

 <li class="customtopnavsearch">                                             <input type="text" id="txtsearch" />                                             <a href="#" class="customsearchbutton">                                                 <img src="search-button.png" alt="search" />                                             </a>                                         </li> 

warp common code in function. bind function click event handler image , on click of enter call method.

function myeventhandler(){    var search = $("#txtsearch").val();             var searchencoded = encodeuricomponent(search);     window.location = "/search.aspx?name=" + searchencoded; }  $(document).ready(function () {      $('.customsearchbutton').on("click","img", myeventhandler);     $("#txtsearch").on("keyup",function (e) {         //if enter pressed call method         if(e.which == 13){             myeventhandler();         }      }); }); 

event.which

for key or mouse events, property indicates specific key or button pressed.


Comments

Popular posts from this blog

gcc - MinGW's ld cannot perform PE operations on non PE output file -

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

c# - Search and Add Comment with OpenXML for Word -