Forum Moderators: open

Message Too Old, No Replies

Submit on ENTER

but not if selecting from a drop-down

         

mike73

8:16 pm on Sep 28, 2008 (gmt 0)

10+ Year Member



I have a form that I want to submit when the user presses ENTER. That's no problem; however, if the user is scrolling through the selections in a drop-down and presses ENTER to make a selection, that also submits the form.

Is there a way to differentiate between an ENTER in the expanded portion of a drop-down, and an ENTER someplace else?

Thanks in advance for any advice :)

httpwebwitch

8:08 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that's a tricky one

you can disable any form submission temporarily by setting its onsubmit event to a function that returns false...

onsubmit=function(){return false;}

the trick is to disable submit while the dropdown is active, and re-enable it when the select dropdown is not. I'm not sure if onblur and onfocus are going to do that for you.

I didn't think select boxes had that problem. Usually when you're keying through options, you can press Enter to select that option... One usually relies on the standard behaviours of the HTML elements because overriding them is nasty business.

Maybe it's possible to capture the Enter key; and when Enter is pressed check if a select box is focused, disable the form submit if true. Just a thought

mike73

7:27 am on Sep 30, 2008 (gmt 0)

10+ Year Member



thanks for the reply :)

Yes, it is tricky. I can't seem to find a way to differentiate the select box from the rest of the control. It seems like they're both treated as one.