Prevent A Form From Being Submitted While Pressing Enter Key
how can we prevent a form from being submitted while pressing enter key. Actually I have a text box and on entering a value on that textbox and clicking enter the textbox2 will ge
Solution 1:
Without looking up the actual code, here's the basic theory behind how I'd do it:
Define an event handler on the document for a key being pressed to call a function.
If the key that triggered the event is the enter/return key, return false
, otherwise return true
.
EDIT: Looks like you already found the answer (as well as some code to do it), so my answer is somewhat unnecessary now.
Solution 2:
Writing 'onKeyPress' of the form like " { var key; if(window.event) key = window.event.keyCode; else key = e.which; //firefox return (key != 13); }
" will work.
Solution 3:
what i do is add onsubmit="return false;"
to the <form>
tag.
this will also disable the submit button however to create a working submit button use
<inputtype="button" value="Submit" onclick="javascript:document.form.submit();" />
Solution 4:
This should work
<formonsubmit="return false;">
//Form elements
</form>
Post a Comment for "Prevent A Form From Being Submitted While Pressing Enter Key"