Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form submits twice when pressing return/enter

I'm using anchors as links, and also I'm binding the enter/return key to submit a form, like this:

$("form[name!=smsform]").bind("keyup", function(e){
if(e.keyCode == 13){
$(this).submit();
});

$("a[title=submit]").click( function(){
$(this).parents("form").submit();
});

However the form submits twice when clicking enter/return using the code above, I need to merge the two snippets - anyone know how to go about this?

like image 698
timkl Avatar asked Jan 22 '23 13:01

timkl


1 Answers

A form will submit automatically when you click enter, there is no need to write the code yourself. If you want to add some testing to the enterkey event before you submit, then you can return false from the callback function to prevent the default browser action.

like image 154
Marius Avatar answered Jan 31 '23 09:01

Marius