By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

How to prevent Form submission if users hit enter.

P: n/a
In my Web Form I have more than one Textbox for user input. If I hit
enter to any Textbox its submitting the form. How can I prevent Form
submission if users hit enter to the textbox? I want to submit the
form only when user will hit submit button.

Thanks for any help.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
pa**************@yahoo.com (Pamela Chatterjee) writes:
In my Web Form I have more than one Textbox for user input. If I hit
enter to any Textbox its submitting the form. How can I prevent Form
submission if users hit enter to the textbox? I want to submit the
form only when user will hit submit button.


Why?

It is customary that browser forms are submitted by pressing return
in a text field. The user will be expecting it to happen. So, why
do you want to prevent the user from using the standard interface of
his browser?

If it is because you have, e.g., form validation code attached to
the submit button, then you should move that to the form elements
onsubmit handler instead.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
In article <b3**************************@posting.google.com >,
pa**************@yahoo.com enlightened us with...
In my Web Form I have more than one Textbox for user input. If I hit
enter to any Textbox its submitting the form. How can I prevent Form
submission if users hit enter to the textbox? I want to submit the
form only when user will hit submit button.

Thanks for any help.


You capture the enter key.
That's been posted on this group before, several times. Take a look at
the archives on google. You have to worry about browsers with that one.
So keep in mind your target browsers.

You also break functionality a user is used to (the browser is SUPPOSED
to do that and some people count on it) - not a good thing for general
internet applications, acceptable for intranet apps, CD-ROMs, or
games...
Always remember that internet applications can be accessed by anyone
with any browser - including those browsers modified or created for the
disabled. Disabling functionality may render your site inaccessible to
the disabled.

-------------------------------------------------
~kaeli~
Jesus saves, Allah protects, and Cthulhu
thinks you'd make a nice sandwich.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.