On a side note... Do you want/need autocomplete becasue it is possible to stop a textfield being capable of autocomplete. I ask simply becasue your example uses a login field and sometimes it's not security concious to allow autocomplete on some login fields. Otherwise you'll just have to log what key was pressed in an external variable EVERYTIME a key is pressed and check that variale at the start of every keypress event. James
________________________________ From: jquery-en@googlegroups.com on behalf of rob303 Sent: Tue 20/01/2009 14:58 To: jQuery (English) Subject: [jQuery] Re: Identify last keeypess Hi James, Thanks for the reply. It's just a standard text input: <input class="login_input" type="text" name="user" value="" /> When the user clicks and starts to type the browser may, depending on what's been entered before, give a list of options. Some users might use the down or up arrow keys to highlight one of the options and then hit submit to select it. This, I think, is standard browser behaviour - unless I have it wrong? Unfortunately for me, hitting enter at that point will submit the form. Any help would be much appreciated! Rob. On Jan 20, 1:56 pm, "James Hughes" <j.hug...@kainos.com> wrote: > Rob, > > Is this some sort of autocomplete text box or is it a select input? > > James > > ________________________________ > > From: jquery-en@googlegroups.com on behalf of rob303 > Sent: Tue 20/01/2009 13:44 > To: jQuery (English) > Subject: [jQuery] Identify last keeypess > > Hi, > > I've been searching the web for an answer to this but haven't been > able to find one. > > I have a form which is using an image as it's submit button and I want > users to be able to submit the form by pressing enter. Simple enough: > > // submit the login form if the user hits enter > $('.login_input').keypress(function(event) { > if(event.keyCode == 13) { > $('#login').submit(); > } > > }); > > That works fine. However, if the user is presented with a list of > options for the text input by their browser and they use the up and > down arrows keys to highlight, then enter to select an option the form > gets submitted. Not ideal! So, my question is how can I identify the > last key press before the user hits enter? Ideally my logic will be > something like: > > $('.login_input').keypress(function(event) { > if(LAST KEYPRESS IS NOT UP OR DOWN ARROW) { > if(event.keyCode == 13) { > $('#login').submit(); > } > } > > }); > > Hopefully, that makes sense! Many thanks in advance for any help. > > Rob. -------------------------------------------------------------------- This e-mail is intended solely for the addressee and is strictly confidential; if you are not the addressee please destroy the message and all copies. Any opinion or information contained in this email or its attachments that does not relate to the business of Kainos is personal to the sender and is not given by or endorsed by Kainos. Kainos is the trading name of Kainos Software Limited, registered in Northern Ireland under company number: NI19370, having its registered offices at: Kainos House, 4-6 Upper Crescent, Belfast, BT7 1NT, Northern Ireland. Registered in the UK for VAT under number: 454598802 and registered in Ireland for VAT under number: 9950340E. This email has been scanned for all known viruses by MessageLabs but is not guaranteed to be virus free; further terms and conditions may be found on our website - www.kainos.com