Disable the Enter Button on Form Javascript
Javascripts > Javascript Forms > Disable the Enter Button on Form
Script Title: Disable the Enter Button on Form
Description: This script disable the [Enter] key when pressed inside chosen fields of your choice. Try filling out the text fields below and pressing [Enter]. Notice how instead of submitting the form, the cursor is instead advanced to the next field.
Example: Available
Copy the following code into your <HEAD></HEAD> tags.<script type="text/javascript">
/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/
function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
</script>
Copy the following code between the <BODY></BODY> tags of your html page.<FORM onsubmit="return false">Name: <INPUT
onkeypress="return handleEnter(this, event)"><BR>Email: <INPUT
onkeypress="return handleEnter(this, event)"><BR>Your comments:<BR><TEXTAREA rows=6 cols=40></TEXTAREA><BR><INPUT type=submit value=Submit>
</FORM>
Enter your name and email address to have this script sent right to your Inbox for later viewing.
© 2023 Javascripts
Now Viewing Disable the Enter Button on Form