August 4, 2014

Call Javascript function on pressing ‘Enter’ key

In most of the pages you might have noticed how you can type your queries into the search box and search by pressing the enter key instead of having to click the ‘Search’ button present in the page.


<input type="text" onKeydown="Javascript: if (event.keyCode==13) Search();">

<input type="button" value="Search" onClick="Search();">

The onClick event of the Search button calls a javascript function named Search(). To have the same function called on pressing the enter key when the cursor is in the text box, we check if the keycode is 13 and subsequently call the Search() function.

No comments:

Post a Comment

Popular Posts