on enter press submit form code example
Example 1: javascript submit form when enter key pressed
document.getElementById("myInputID").addEventListener("keyup", function(event) {
if (event.keyCode === 13) {
document.getElementById("myFormID").submit();
return false;
}
});
Example 2: how to new tab disable after hit enter in javascript
(function( $ ){
$.fn.enterAsTab = function( options ) {
var settings = $.extend( {
'allowSubmit': false
}, options);
this.find('input, select').live("keypress", {localSettings: settings}, function(event) {
if (settings.allowSubmit) {
var type = $(this).attr("type");
if (type == "submit") {
return true;
}
}
if (event.keyCode == 13 ) {
var inputs = $(this).parents("form").eq(0).find(":input:visible:not(disabled):not([readonly])");
var idx = inputs.index(this);
if (idx == inputs.length - 1) {
idx = -1;
} else {
inputs[idx + 1].focus();
}
try {
inputs[idx + 1].select();
}
catch(err) {
}
return false;
}
});
return this;
};
})( jQuery );