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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With