Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Press enter submits form
- From: javascript@xxxxxxxxxx (Harry Love)
- Subject: [Javascript] Press enter submits form
- Date: Tue, 27 Aug 2002 12:14:02 -0700
<snip>
Yeah but that's why I want to use Javascript to prevent that- I'm pretty
sure it's possible. Something like on key press submit() or something.
But
maybe it's not possible?
</snip>
Ah, preventing! Well, if the purpose is to prevent people from
prematurely submitting the form, you could also use the onsubmit event
handler to validate the forms. Roughly, onsubmit, if a form field is
incomplete, alert the user to complete the form, put focus on the empty
text field, etc. Or, confirm a submission using onsubmit="confirm('Do
you want to submit the form?')".
And you're right, you can use onkeydown, onkeypress, and onkeyup to pass
the event object to a function from a text input or textarea. The
[enter] key is captured by the event object (Decimal Character Code 13).
I've never tried it myself, but a Google search appears to produce
favorable results. A search for "javascript enter key" produced this
(sorry if the URL wraps):
http://www.google.com/search?sourceid=navclient&q=javascript+enter+key
The second link looks like a winner.
Regards,
Harry
- Prev by Date: [Javascript] Specific areas for the action of the mouse
- Next by Date: [Javascript] HTML Form-Based file upload problem....
- Previous by thread: [Javascript] Press enter submits form
- Next by thread: [Javascript] IE popup object
- Index(es):