• Advertisement
Sign in to follow this  

[web] Cycling through input boxes

This topic is 4493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way to code a set of 10 x 10 inpux boxes such that the arrows keys can make the curser jump from one box to the next (similar to how excel works)? Currently, the only way I know of moving the cursor in an HTML form is to either use the mouse or press the tab key. Both methods I find to be highly inefficient. I really don't care what language I'd have to code it in (html, Xhtml, dhtml, flash, etc), but the simplier the better. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
You might be able to do it in javascript, trapping keys and setting the focus or something.

That's all i got.

ace

Share this post


Link to post
Share on other sites
It should definitely be possible to write a javascript event handler which makes this happen.

To hook the events initially, you'd want to loop through all the 100 boxes. This can be done with a for loop on the form object, whose members will include the text boxes (input elements).

Alternatively you could use getElementsByTagName("input") to use a DOM1-style thing.

Then you should set your event handler for onkeypress (all lower case, not onKeyPress or onKEYPress or anything like that).

Once the event handler fires, you'll need to figure out
- What key was pressed (i.e. was it one you're interested in)
- Where the cursor is now
- Where you want to move it to

and then move it accordingly, probably by calling the focus() method on the relevant element.

Capturing event parameters is somewhat browser-specific (well, insofar as IE does it differently from every other browser). However it's not that difficult to code something which copes with both types.

Cancelling an event is also somewhat browser-specific (and maybe can't be done at all). You should be able to get away without cancelling the event in this case though.

Mark

Share this post


Link to post
Share on other sites
Hmm... i guess that would work. Sounds like its going to be a big pain in the butt though. :\

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement