How to know when an enter key press is used to select an item in thebrowser's context dropdown and n

  • Thread starter Daniel Smedegaard Buus
  • Start date
D

Daniel Smedegaard Buus

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 :)
 
D

Daniel Smedegaard Buus

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
 
D

David Mark

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

David Mark

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?!
 
T

Thomas 'PointedEars' Lahn

Daniel said:
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
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top