/ Published in: JavaScript

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<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>
URL: http://www.dynamicdrive.com/dynamicindex16/disableenter.htm
Comments
