I'm developing a web project in C #, and for forms I'm using Html.BeginForm
. How do I disable submit by pressing the Enter key? Can you do without javascript?
I'm developing a web project in C #, and for forms I'm using Html.BeginForm
. How do I disable submit by pressing the Enter key? Can you do without javascript?
Without javascript
I find it difficult to achieve, you will need a script Client Side
to check the click. With jQuery
you can do the following:
$(document).ready(function() {
$('form#exemplo').bind("keypress", function(e) {
if ((e.keyCode == 10)||(e.keyCode == 13)) {
e.preventDefault();
}
});
});
or
$(document).ready(function() {
$('form#exemplo').keypress(function(e) {
if ((e.keyCode == 10)||(e.keyCode == 13)) {
e.preventDefault();
}
});
});
If you have a Submit button on your form it should be marked as "default" and the action of typing Enter will execute the marked component as such.
You can also turn the submit into button.
<input type='button'>
And submit the form via JS.
$('#form_id').submit();