Detecting Tab Key Help Needed

R

Ralph Freshour

I'm trying to use JS to move the cursor from my user login text field
to the password text field - I've put the onKeyPress() event in the
user input tag but then I press the Tab key the cursor doesn't move -
can someone please help me with this? Thanks...

function detect_tab_key()
{
var key_code = window.event.keyCode;
if (key_code == 9)
{
document.forms[0].frm_password.focus();
document.forms[0].frm_password.select();
}
}
 
V

VK

Tab key is a "system button". It means that you cannot reprogram it, the
default system behavior will always override your script (the same way the
F1 key always returns browser help, no matter what action did you attach to
this).

Solution are:
1. Simply place login and password one after another in the form. It will
give you the same effect without any programming.
2. If your form layout ABSOLUTELY requires to put some extra stuff between
these fields, than use TABINDEX property (IE 4.x and higher):

<input name="field1" ... tabindex="1">
<input name="field2" ... tabindex="3">
<input name="field3" ... tabindex="2">

Being on field1, on tab press the focus will jump on field3 first
 

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
474,082
Messages
2,570,588
Members
47,209
Latest member
Ingeborg61

Latest Threads

Top