473,786 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

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.keyCo de == 13) { try
{ event.cancelBub ble = true; event.returnVal ue = 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
4 2962
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(fun ction() { 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="retur n
false;" to the form's tag.

Cheers,
Daniel
Aug 7 '08 #2
On Aug 7, 3:14*am, Daniel Smedegaard Buus <danielb...@gma il.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.keyCo de == 13) { try
{ event.cancelBub ble = true; event.returnVal ue = 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
On Aug 7, 5:11*am, Daniel Smedegaard Buus <danielb...@gma il.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(fun ction() { 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="retur n
false;" to the form's tag.
Is it?!
Aug 7 '08 #4
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.keyCo de == 13) { try
{ event.cancelBub ble = true; event.returnVal ue = false; } catch(e)
{}; }" trick to manually submit the form.
Utter nonsense.
However, this introduces another problem:
As expected.
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Aug 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10180
by: Ian Davies | last post by:
Hello In a php file I have a drop down list with index numbers in whos default value is feed into an sql query that filters records from my database and displays them in an html table. Trouble is this happens as soon as the php is run so bringing up the same records filtered from the default index. Also when I select a new index no from the drop down list is doesnt refilter the records bringing up the ones for the new list. It still...
8
2585
by: Galina | last post by:
Hello I have 6 dependent list boxes on my ASP page:  Faculty;  Lecturer;  Course;  Course occurrence;  Group;  Week commencing date. When faculty is selected, lists of lecturers and courses are populated. When course is selected, lists of occurrences, groups and
6
10697
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different functionalities: 1. After pressing the back button, the item you selected in the dropdown is still selected.
6
3816
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many user get used to click "enter" key to submit a form. How can I use "enter" key to submit/postback in ASP.NET. Thank, Guoqi Zheng
9
1890
by: Coleen | last post by:
Hi All :-) I am desperately looking for some help/information on how to direct page flow. Forget what I have done - here's what I need to do: I have a large ASPX.Net - VB.Net web application (around 35-40 pages) that once the user logs in, I need to direct them to the correct page, depending on what they select from the directory. In other words...when they login, if they are a new user, a new account screen comes up and from there a...
3
5418
by: Patrick [MSFT] | last post by:
Let me preface this with the goal I'm trying to achieve is mimic a feature of another language (Dexterity used by Microsoft Dynamics) and so while a filling a drop down list is a workable solution I'd rather do it like Microsoft Dynamics does and use separate textbox and lookup button. What I have is, simply, is a C# winform, a textbox and a pushbutton. On the textbox, on the validating event of the textbox I check my customer table...
4
7630
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches. Recently somebody pointed out to me that you can't just press ENTER anymore after typing in the TextBox but that you HAVE to click on the submit Button WITH THE MOUSE for it to work. After some initial troubleshooting I discovered that it's only...
10
6978
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration of section c. Not sure where went wrong as the web page displayed internal server error. Also, what is the error 543? and error 2114. Where to find the list of errors in websites as it is not the standard apache error. I could not find...
0
1430
vikas251074
by: vikas251074 | last post by:
I am using Oracle 9i and ASP I have empno, empname, designation, category, dob. Category have two option 'S' or 'O' When I enter empno, empname, designation, category and dob and when I press enter key all the data remains on the form but only list value is lost. what should I do ? How can I solve this. <%@ Language=VBScript%>
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.