Submit form with Enter key without submit button?
Change #form to your form's ID
$('#form input').keydown(function(e) {
if (e.keyCode == 13) {
$('#form').submit();
}
});
Or alternatively
$('input').keydown(function(e) {
if (e.keyCode == 13) {
$(this).closest('form').submit();
}
});
$("input").keypress(function(event) {
if (event.which == 13) {
event.preventDefault();
$("form").submit();
}
});
Jay Gilford's answer will work, but I think really the easiest way is to just slap a display: none;
on a submit button in the form.
@JayGuilford's answer is a good one, but if you don't want a JS dependency, you could use a submit element and simply hide it using display: none;
.