Enter Key on Text Box
by Jaganathan
HTML
Form:
<form action="#" id ="sub" >
<input type="text" name="txt" />
</form>
<br/>
Normal:
<input id="text" type="textbox" value="">
<input id="btn" type="button" value="GO!">
JavaScript
$(function () {
$('#text').keypress(function (event) {
if (event.which == 13) {
alert("enter pressed");
//return false;
}
});
$("#btn").click(function () {
var e = jQuery.Event('keypress');
e.which = 13; // #13 = Enter key
$("#address").focus();
alert("button pressed");
});
$("#sub").on("submit", function(){
alert("FORM WAS SUBMITTED");
return false; //Otherwise the form will be submitted
});
});