Onkeydown event dosen't work when TAB key is pressed

Onkeydown event dosen't work when TAB key is pressed

Page 1 of 1

6 Replies - 5947 Views - Last Post: 08 October 2007 - 12:17 PM

#1 subratparida  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-July 07

Onkeydown event dosen't work when TAB key is pressed

Posted 05 October 2007 - 11:56 AM

Hi,

I have one html form and I want to move cursor to another field to a different tabindex order using TAB key. I wrote a function "moveto()", and it is called on field EMAIL on event onkeydown, the cursor should move to field 'realname', but it doesn’t work.

Dose anyone know how it can be fixed?

<html>
<head>
<script type="text/javascript">
function moveto(){
	  document.forms[0].elements['realname'].focus()
}
</script>
</head>
<body>
<FORM ACTION="" METHOD=POST>
<TABLE BORDER CELLPADDING=3 CELLSPACING=5 BGCOLOR="#FFFFCC">
<TR>
	 <TD>name: <INPUT NAME="realname" TABINDEX=1></TD>
	 <TD ROWSPAN=4>comments<BR>
	 <TEXTAREA COLS=25 ROWS=5 TABINDEX=4></TEXTAREA></TD></TR>
<TR> <TD>email: <INPUT NAME="email" TABINDEX=3 onkeydown="moveto()"></TD></TR>
<TR> <TD>department: <SELECT NAME="dep" TABINDEX=5>
	 <OPTION VALUE="">...
	 <OPTION VALUE="prd">Production</SELECT></TD></TR>
</TABLE>
</FORM>
</body>
</html>


Thanks,
Subrat

[mod edit] use code tags! :angry:

Is This A Good Question/Topic? 0
  • +

Replies To: Onkeydown event dosen't work when TAB key is pressed

#2 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 05 October 2007 - 12:23 PM

Moved to Javascript forum.
Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 05 October 2007 - 12:42 PM

Hi, try changing this line document.forms[0].elements['realname'].focus()
into
document.forms[0].elements['email'].focus()

And yes, please use code tags when posting code.

This post has been edited by PennyBoki: 05 October 2007 - 12:43 PM

Was This Post Helpful? 0
  • +
  • -

#4 subratparida  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-July 07

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 06 October 2007 - 01:15 PM

Thanks for reply.

I don't think it will work if we replace the field name with 'email'. I want when TAB key is pressed the cursor to move to field 'Name'.

This is just a test html form I have created to test the function to check how it works.

We have one requirement, for example, if email field (tabindex = 3) hold a value, if TAB key is pressed the cursor should move to 'tabindex = 6' instead of 'tabindex = 4'.

I know it can be done in onchange event in email field, it works but problem is if user go back to 'tabindex=1' then TAB again come back to email field, then TAB again on email field without changing the value of email field, the cursor goes to tabindex=4 becasue it dosen't fire onchnage event, that i don't want, it should go to tabindex=6. It can be only done in onkeydown event.

This post has been edited by subratparida: 06 October 2007 - 01:16 PM

Was This Post Helpful? 0
  • +
  • -

#5 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 06 October 2007 - 01:22 PM

View Postsubratparida, on 6 Oct, 2007 - 01:15 PM, said:

I don't think it will work if we replace the field name with 'email'. I want when TAB key is pressed the cursor to move to field 'Name'.

You don't think but did you try it?
I'm not a JS guru but I think it works this way, with pressing the TAB key it goes from item to item. Please try it.
Was This Post Helpful? 0
  • +
  • -

#6 subratparida  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 17-July 07

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 08 October 2007 - 11:57 AM

Yes I tried, it didn't work.
Was This Post Helpful? 0
  • +
  • -

#7 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: Onkeydown event dosen't work when TAB key is pressed

Posted 08 October 2007 - 12:17 PM

View Postsubratparida, on 8 Oct, 2007 - 11:57 AM, said:

Yes I tried, it didn't work.

Sorry about that I misunderstood *ashamed*

Now this is what I did but it's not the best solution:
(It was the keyup thing :))


<html>
<head>
<script type="text/javascript">
function moveto(){
document.forma.realname.focus()
}
</script>
</head>
<body>
<FORM name="forma" ACTION="" METHOD=POST>
<TABLE BORDER CELLPADDING=3 CELLSPACING=5 BGCOLOR="#FFFFCC">
<TR>
<TD>name: <INPUT NAME="realname" TABINDEX=1></TD>
<TD ROWSPAN=4>comments<BR>
<TEXTAREA COLS=25 ROWS=5 TABINDEX=4></TEXTAREA></TD></TR>
<TR> <TD>email: <INPUT NAME="email" TABINDEX=3 onkeyup="moveto()" onkeydown="moveto()"></TD></TR>
<TR> <TD>department: <SELECT NAME="dep" TABINDEX=5>
<OPTION VALUE="">...
<OPTION VALUE="prd">Production</SELECT></TD></TR>
</TABLE>
</FORM>
</body>
</html>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1