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

How to know when an enter key press is used to select an item in thebrowser's context dropdown and not to submit a form?

P: n/a
Hey :)

I'm trying to figure this one out, and it's a bit tricky.

I have a "tip a friend" form that's submitted via AJAX. When the user
presses enter inside one of the form's input fields, the form should
submit. This works out-of-the-box in FF and Safari, probably others
too, but not in IE6.

This is why I've used the "if(event.keyCode == 13) { try
{ event.cancelBubble = true; event.returnValue = false; } catch(e)
{}; }" trick to manually submit the form.

However, this introduces another problem: In FF, when I write in an
input field, I get a drop-down underneath with a list of previous
things I entered in similar input fields (I'm guessing input fields
with the same name tag). Now, if I pick one of these with my arrow
keys and then press enter to select it, not only is it selected, but
the form is also submitted, which is not the expected behavior :)

I'm wondering if there's any way to know if such a dropdown is open
and has focus so that I can prevent submitting the form when this is
the case? If any of you know, please tell me :)

Thanks in advance,
Daniel :)
Aug 7 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Okay guys, problem solved. This is tricky business indeed, but I ended
up with not using the event.keyCode hack anyway.

I've added
form.submit(function() { return false; })
to my form ajaxifying code, which prevents IE6 from submitting the
form on enter key presses, while real browsers work fine and submit
via ajax on enter key, and the drop downs are indeed supported once
more :) As I see it, if you're still using IE6, not being able to
submit a form by hitting enter is the least of your problems ;)

Btw, the code above is the equivalent of adding onsubmit="return
false;" to the form's tag.

Cheers,
Daniel
Aug 7 '08 #2

P: n/a
On Aug 7, 3:14*am, Daniel Smedegaard Buus <danielb...@gmail.com>
wrote:
Hey :)

I'm trying to figure this one out, and it's a bit tricky.

I have a "tip a friend" form that's submitted via AJAX. When the user
presses enter inside one of the form's input fields, the form should
submit. This works out-of-the-box in FF and Safari, probably others
too, but not in IE6.

This is why I've used the "if(event.keyCode == 13) { try
{ event.cancelBubble = true; event.returnValue = false; } catch(e)
{}; }" trick to manually submit the form.
I'm not familiar with that "trick." It looks like nonsense to me,
regardless of the (missing) context. It doesn't appear to submit
anything, manually or otherwise.
>
However, this introduces another problem: In FF, when I write in an
Not a shock. Browsers don't really do tricks. It is best to
understand the code you write.
Aug 7 '08 #3

P: n/a
On Aug 7, 5:11*am, Daniel Smedegaard Buus <danielb...@gmail.com>
wrote:
Okay guys, problem solved. This is tricky business indeed, but I ended
Only when you use "tricks."
up with not using the event.keyCode hack anyway.
I don't know that hack either.
>
I've added
* * form.submit(function() { return false; })
Sheer nonsense, any way you look at it.
to my form ajaxifying code, which prevents IE6 from submitting the
form on enter key presses, while real browsers work fine and submit
IE6 is not the problem. You are the problem.
via ajax on enter key, and the drop downs are indeed supported once
more :) As I see it, if you're still using IE6, not being able to
submit a form by hitting enter is the least of your problems ;)

Btw, the code above is the equivalent of adding onsubmit="return
false;" to the form's tag.
Is it?!
Aug 7 '08 #4

P: n/a
Daniel Smedegaard Buus wrote:
I'm trying to figure this one out, and it's a bit tricky.
It is not if one knows what one does. You do not, but hopefully that is
going to change.
I have a "tip a friend" form that's submitted via AJAX. When the user
presses enter inside one of the form's input fields, the form should
submit. This works out-of-the-box in FF and Safari, probably others
too, but not in IE6.
This is because you are handling a key* event of the control and not the
`submit' of the form.
This is why I've used the "if(event.keyCode == 13) { try
{ event.cancelBubble = true; event.returnValue = false; } catch(e)
{}; }" trick to manually submit the form.
Utter nonsense.
However, this introduces another problem:
As expected.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 7 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.