Jump to content

Enter To Focus On Next Field.


Jiraiya-Sama
 Share

Recommended Posts

Hi all,I have a question about using enter to focus a new field.so, basically, i have 5 text field and instead of using TAB to jump to next text field, i need to use ENTER.It is actually the same effect on this site.http://javascript.internet.com/forms/enter-key-focus.htmlbut too bad it only works in IE, and i need to make FF / Chrome work.I change from event.keyCode to event.which, but every time i click ENTER, instead of jumping to next text field, it submit the form....May I ask if anyone has any idea how this can be done?Thanks very much for your time. :)

Link to comment
Share on other sites

make it return false until all fields are complete and auto focus in the first blank/incomplete fieldORif you are feeling lazy, you can copy this code. I tried it with FF and it works just fine:http://www.dynamicdrive.com/dynamicindex16/disableenter.htm

Link to comment
Share on other sites

hows this:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Untitled Document</title></head><body><script type="text/javascript">function keypressed(e,x){e = e? e : window.event;var Key = e.keyCode? e.keyCode : e.which? e.which : null;if (Key == 13){alert("Enter button Pressed - Press the damn 'Submit Now' button Fool!")if(e.preventDefault)e.preventDefault(); //Prevent form being submitted e.returnValue=false; //Prevent form being submittede.cancel = true; //Prevent form being submittedvar next=x.tabIndex;if (next<document.getElementById("myForm").length) { document.getElementById("myForm").elements[next].focus(); }e.tabIndex};};</script><form id="myForm"><input type="text" tabindex="1" onkeypress="keypressed(event,this)" /><input type="text" tabindex="2" onkeypress="keypressed(event,this)" /><input type="text" tabindex="3" onkeypress="keypressed(event,this)" /><input type="submit" value=" Submit Now" /></form></body></html>

Edited by dsonesuk
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...