470,596 Members | 1,528 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

prevent form submit ...

I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know which
functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the
form is submitted, how could prevent that ?

thanks, ...
Lloyd
Nov 17 '05 #1
6 1810
You can intercept the client side enter keypress event of the text box and
then click the correct button using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx
And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know which functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the
form is submitted, how could prevent that ?

thanks, ...
Lloyd

Nov 17 '05 #2
hehe, regarding your samples I found I could simply write:
onkeydown="if ((event.which && event.which == 13) ||
(event.keyCode && event.keyCode == 13))
return false;"

and that remove the form triggering !
hhmm.. maybe I could a default button too... anyway thanks :-)
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
You can intercept the client side enter keypress event of the text box and
then click the correct button using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx
And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know

which
functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the
form is submitted, how could prevent that ?

thanks, ...
Lloyd


Nov 17 '05 #3
If the user hits enter it triggers exactly the same action as clicking the
default submit button. What exactly are you trying to accomplish? If you
don't want to allow the user to submit the form don't create any submit
buttons... And if for some reason you have a script in your onclick event on
the submit button then just move it to onsubmit event of the form...

Jerry

"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know which functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the
form is submitted, how could prevent that ?

thanks, ...
Lloyd

Nov 17 '05 #4
Right, that was one of the examples in the links I gave you.
I'm glad it worked out well for you.

--
Steve C. Orr, MCSD
http://Steve.Orr.net
"Lloyd Dupont" <ll***@galador.net> wrote in message
news:uu**************@tk2msftngp13.phx.gbl...
hehe, regarding your samples I found I could simply write:
onkeydown="if ((event.which && event.which == 13) ||
(event.keyCode && event.keyCode == 13))
return false;"

and that remove the form triggering !
hhmm.. maybe I could a default button too... anyway thanks :-)
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
You can intercept the client side enter keypress event of the text box and then click the correct button using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx
And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know

which
functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the form is submitted, how could prevent that ?

thanks, ...
Lloyd



Nov 17 '05 #5
PJ
on a wider note...this book will payback after about 1 day of javascript
coding....

Javascript & DHTML Cookbook ( Danny Goodman )
http://www.bookpool.com/.x/hywrfgtqor/sm/0596004672

"Lloyd Dupont" <ll***@galador.net> wrote in message
news:uu**************@tk2msftngp13.phx.gbl...
hehe, regarding your samples I found I could simply write:
onkeydown="if ((event.which && event.which == 13) ||
(event.keyCode && event.keyCode == 13))
return false;"

and that remove the form triggering !
hhmm.. maybe I could a default button too... anyway thanks :-)
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:ex**************@TK2MSFTNGP10.phx.gbl...
You can intercept the client side enter keypress event of the text box and then click the correct button using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx
And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know

which
functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the form is submitted, how could prevent that ?

thanks, ...
Lloyd



Nov 17 '05 #6
I have multiple section on my web page.
like 'unregister section' and 'update profile section'

so I could not 'just submit' the form.
I need the user to click on one button, so I know if it unregister, or if it
just update on its profile.

otherwise, mmhh.. what would you do ?

and no, I rather have them both on the same page than on 2 empty otherwise
page.

"Jerry III" <je******@hotmail.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP09.phx.gbl...
If the user hits enter it triggers exactly the same action as clicking the
default submit button. What exactly are you trying to accomplish? If you
don't want to allow the user to submit the form don't create any submit
buttons... And if for some reason you have a script in your onclick event on the submit button then just move it to onsubmit event of the form...

Jerry

"Lloyd Dupont" <ll***@galador.net> wrote in message
news:OC**************@tk2msftngp13.phx.gbl...
I have a web form with multiple part.
I do want the user to click the submit button to post back, so I know

which
functionality was triggered.

unfortunately, when the focus is any text box, if the user hit ENTER the
form is submitted, how could prevent that ?

thanks, ...
Lloyd


Nov 17 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.