/    Sign up×
Community /Pin to ProfileBookmark

TABINDEX and next input field

i have an unknown numberof inupt text field and i give all of them a TABINDEX value from 1 to n
now i ant to be able to move from one to the other using the given tab order but t with the keybord arrows as well
how cn i do that?
thnaks i nadvance
peleg

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — A combination of onKeyPress, event.keyCode & element.focus() should handle the task.
Copy linkTweet thisAlerts:
@pelegk1authorApr 14.2005 — if i have reached the first or the lasttext box to know its lst and go to the first?
Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — if i have reached the first or the lasttext box to know its lst and go to the first?[/QUOTE]

There are many ways to do this, one of the simplest probably being marking the last and the first input box by a unique ID ("last" and "first" or whatever) and the checking for this in the script [if (inputfield.id == "last"){}]. Don't really know how this fits into your scenario - whether you are not already using the id properties of the fields etc..

The "best" (but also most complicated) way of doing this would probably be writing a universal script, that determines the first/last status by either the tabIndex property (inputfield.tabIndex), or simply by the sequence of the input elements in the form.
Copy linkTweet thisAlerts:
@pelegk1authorApr 14.2005 — second how can in an input text i can check if one of the arrows was pressed?
Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — [code=php]<input type="text" onKeyDown="checkArrow(event);" />
// UPDATED: Was originally posted with onKeyPress, but apparently there are problems with this in IE - onKeyDown seems to solve the problem.

function checkArrow(event) {
// left: 37, right: 39, up: 38, down: 40
if (event.keyCode == 37)
alert("You pressed the LEFT ARROW key.");
}
[/code]

Haven't tested this code, but it should work.. ?
Copy linkTweet thisAlerts:
@pelegk1authorApr 14.2005 — byt the way how do i check thay the CTRL is pressed to?
Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — Sorry, apparently in Internet Explorer the onKeyPress is not triggered by pressing the arrow keys.. This works in Mozilla, though. Let me check, if there's some other way..
Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — Sorry, apparently in Internet Explorer the onKeyPress is not triggered by pressing the arrow keys.. This works in Mozilla, though. Let me check, if there's some other way..[/QUOTE]
Ok, I found out that the onKeyPress doesn't always (or ever) capture the arrow key presses. Instead use onKeyDown (or onKeyUp).
Copy linkTweet thisAlerts:
@kitofersApr 14.2005 — byt the way how do i check thay the CTRL is pressed to?[/QUOTE]
The event object has the following boolean properties:

ctrlKey, altKey, shiftKey.

So, to check for a ctrl + left:
[code=php]if (event.keyCode == 37 && event.ctrlKey)
alert("You pressed CTRL + LEFT.");[/code]
Copy linkTweet thisAlerts:
@pelegk1authorApr 17.2005 — thnkas
×

Success!

Help @pelegk1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...