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

default button on form

P: n/a
hi,

how to make some push button default on the form? for instance, I've got 2
buttons (Submit, Cancel). submit is on the left, cancel on the right side.
on enter key pressed, cancel button is processed - wrong. so, how to make a
button default (when one presses ENTER then it's processed onClick event)?

thanks,
bj

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You can intercept the client side enter keypress event of the text box and
then click do what you want 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, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Bratislav Jevtic" <in*******@ptt.yu> wrote in message
news:eD****************@tk2msftngp13.phx.gbl...
hi,

how to make some push button default on the form? for instance, I've got 2
buttons (Submit, Cancel). submit is on the left, cancel on the right side.
on enter key pressed, cancel button is processed - wrong. so, how to make a button default (when one presses ENTER then it's processed onClick event)?

thanks,
bj

Nov 17 '05 #2

P: n/a
From MSDN:

When there is more than one INPUT type=submit in the same form, pressing
enter submits the form using the first INPUT type=submit, unless another
INPUT type=submit has focus. When another INPUT type=submit has focus,
pressing enter submits the form using that INPUT type=submit.

If you don't like this behavior, you can use JavaScript to trap the
OnKeyPress event, and if it is the enter key (13), fire the click method of
the button you want to be the default.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows XP
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Bratislav Jevtic" <in*******@ptt.yu> wrote in message
news:eD****************@tk2msftngp13.phx.gbl...
hi,

how to make some push button default on the form? for instance, I've got 2
buttons (Submit, Cancel). submit is on the left, cancel on the right side.
on enter key pressed, cancel button is processed - wrong. so, how to make a button default (when one presses ENTER then it's processed onClick event)?

thanks,
bj

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.