Forms, javascript, focus, and the Enter key

P

Patrick

I have a form filled with 6-7 text fields. By default, the Enter key
will submit the form (even if I set focus to a specific field on the
page load).

I use the onSubmit event to perform some data validation. If there is
a problem with any of the fields, I set focus on the field with the
focus() and do a select() before returning false to the onSubmit.
This, of course, causes the field in question to be highlighted with
focus in the field.

However, at this point, pressing the Enter button will not re-submit
the form. Anyone know why this is?

I had suspected that by putting focus in the field, I was making the
field the "activeElement", so the keystroke of Enter was acting as a
CR, but since it was a one line input type of text, I wasnt noticing.
However, when I set focus on the field during the onLoad() of the
page, it works fine.

Any comments? Workarounds?

Thank you,
Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top