-
Form Subit - JavaScript
I need assistance using JavaScript to run a JS function when a form is submitted. When the submit button is pressed, the form runs the function using the onClick method.
However, I also need this function to run when someone uses the 'Enter' key to submit the form, instead of pressing the 'Submit' button. Any assistance on how to do this would be much appreciated. Thanks!
-
Include this function within Javascript tags...
Code:
function CaptureKey(theFormObj)
{
var key=window.event.keyCode;
if (key==13)
document.FormName.submit();
}
in each of the elements in the form add this attribute..
onkeypress='CaptureKey("Formname")'
For Ex:
<input type=text onkeypress='CaptureKey("LogForm")'>
- Jemima.
-
Thanks for the prompt reply! I'll give it a shot, much appreciated.