/    Sign up×
Community /Pin to ProfileBookmark

Setting keypress.keycode to shift-tab

Does anyone know how to for example capture the up arrow and turn it into the shift tab?

I have a client who wants to arrow up and down thru the form.

Thanks in advance!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@HaganeNoKokoroOct 02.2004 — This example accomplishes the same effect. It requires that your form elements have ids "t1", "t2", ... Also, if you have a gap, like you have "t1", "t2", "t4" but no "t3", then it will not get past the "t2" element.
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 STRICT//EN" "http://www.w3.org/TR/HTML4/strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Form Up/Down Navigation Example&lt;/title&gt;
&lt;script type="text/javascript"&gt;
var cTabIndex=1;
function changeTab(event) {
if(event==null) event=window.event;
switch(event.keyCode) {
case 38:
//up key
if(cTabIndex&lt;=1) return;
cTabIndex--;
break;
case 40:
//down key
if(document.getElementById("t"+(cTabIndex+1))==null) return;
cTabIndex++;
break;
default:
return;
break;
}
document.getElementById('t'+cTabIndex).focus();
}
document.onkeydown=changeTab;
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="maincontent"&gt;
&lt;form method="GET" action=""&gt;
&lt;div&gt;
&lt;input type="text" id="t1"/&gt;&lt;br/&gt;
&lt;input type="text" id="t2"/&gt;&lt;br/&gt;
&lt;input type="text" id="t3"/&gt;&lt;br/&gt;
&lt;input type="text" id="t4"/&gt;&lt;br/&gt;
&lt;/div&gt;
&lt;/form&gt;

&lt;form method="GET" action=""&gt;
&lt;div&gt;
&lt;input type="text" id="t5"/&gt;&lt;br/&gt;
&lt;input type="text" id="t6"/&gt;&lt;br/&gt;
&lt;input type="text" id="t7"/&gt;&lt;br/&gt;
&lt;input type="text" id="t8"/&gt;&lt;br/&gt;
&lt;/div&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
×

Success!

Help @lcgray 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.21,
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,
)...