Automated Change of focus

B

bunch92

Hi guys

The code below will be used to fill in a crossword grid.
When a user types a letter, focus is changed to next cell in the grid.

My code doesn't work and I would be grateful if you could help me ...

The script is :

function changefocus(theevent,thetarget)
{
if (theevent > 64 && theevent < 91){cross1.thetarget.focus();}
}


Part of the HTML is :
<form name="cross1">
<input type="text" name="A1" onKeyUp="changefocus(event.keyCode,'A2');">
<input type="text" name="A2" onKeyUp="changefocus(event.keyCode,'A3');">
<input type="text" name="A3" onKeyUp="changefocus(event.keyCode,'A1');">
</form>



Thank you,
 
L

Lee

bunch92 said:
Hi guys

The code below will be used to fill in a crossword grid.
When a user types a letter, focus is changed to next cell in the grid.

My code doesn't work and I would be grateful if you could help me ...

The script is :

function changefocus(theevent,thetarget)
{
if (theevent > 64 && theevent < 91){cross1.thetarget.focus();}
}


Part of the HTML is :
<form name="cross1">
<input type="text" name="A1" onKeyUp="changefocus(event.keyCode,'A2');">
<input type="text" name="A2" onKeyUp="changefocus(event.keyCode,'A3');">
<input type="text" name="A3" onKeyUp="changefocus(event.keyCode,'A1');">
</form>

If you don't mind that it won't work in Netscape or Firefox,
it looks like all you need to do is change:
cross1.thetarget.focus()
to:
cross1.elements[thetarget].focus()

If you want it to work more generally, you need to change
that to:
document.cross1.elements[thetarget].focus()
and you need to change:
event.keyCode
to:
event.keyCode|event.charCode
 
B

bunch92

Lee said:
If you want it to work more generally, you need to change
that to:
document.cross1.elements[thetarget].focus()
and you need to change:
event.keyCode
to:
event.keyCode|event.charCode


It works perfectly.
Thank you very much Lee
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top