Prevent Enter From Submitting Form

Using a form with several text fields and a submit button? Want to force the user to use the submit button instead of the ENTER key? Disable the ENTER Key!

Instead of using
<input type="submit" value="Submit">
Use this instead
<input type="button" value="Submit" onClick="call a javascript function">

In your javascript function, just use
<script>
   document.formname.submit();
</script>


Sometimes writing an OnClick doesn't work. Try this instead.
In the body of the page write this
<BODY onKeyPress="KeyPress()">

The function KeyPress() should look like this. This will disable the enter key on that page.
<script>
function KeyPress()
{
//alert(window.event.keyCode)
if (window.event.keyCode == 13)
window.event.keyCode =0;
}
</script>



javascrtipt no enter disable enter key force submit


Back To Top
© 1998 - 2024 psacake.com
Version 7.21 | Advertise on this site