Is there any reason you have to hook and test for the enter key?
Couldn't you simply add a
<input type="submit" />
to your form and have it naturally be submitted when enter is pushed? You could even then hook the form's onsubmit
action and call a validation function from there if you wanted...
You could even use the onsubmit
as a test to see if your form is being submitted, but it won't work if you call form.submit()
.