How to prevent Form submission if users hit enter.

P

Pamela Chatterjee

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.
 
K

kaeli

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
-------------------------------------------------
 
L

Lasse Reichstein Nielsen

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
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top