Return to Snippet

Revision: 19858
at November 2, 2009 10:40 by stancox


Initial Code
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah([email protected])
* 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>

<!-- HTML -->
<form>
<input type="text" onkeypress="return handleEnter(this, event)"><br>
<input type="text" onkeypress="return handleEnter(this, event)"><br>
<textarea>Some text</textarea>
</form>

Initial URL
http://www.dynamicdrive.com/dynamicindex16/disableenter.htm

Initial Description

                                

Initial Title
Disable "Enter" Key in Form script

Initial Tags
form

Initial Language
JavaScript