Handling Enter press on filling html input (jQuery)
Sometimes it is necessary to intercept an event when the user types some text. For example, a user fills in a search field and presses Enter to confirm his action.
If you need to do something by pressing the Enter button, you need to write a handler:
$(document).ready(function () {
$("#inputId").keydown(function (e) {
if (e.keyCode == 13) { //do something
}
});
});
In this example “13" is the code of the Enter button;
You can substitute the code of any other button instead of 13.
<input type="text" id="inputId" name="my_name" value="" />
**inputId** - must match the ID in input
Comments