/    Sign up×
Community /Pin to ProfileBookmark

Modifying a hotkey-to-#target script for multiple keys

Hiya! Thanks in advance to anyone willing to help me or even read this!

What I’m trying to do is hotkey items on a long list so that anywhere on the page, the user can push the letter “g” and be taken to the first list item that starts with “g,” and so on.

I found this code on several sites —

[code=php]
<script language=”JavaScript1.2″>

var hotkey=97
var destination=”#target”
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function goitem(e){
if (document.layers){
if (e.which==hotkey)
window.location=destination
}
else if (document.all){
if (event.keyCode==hotkey)
window.location=destination
}
}
document.onkeypress=goitem

</script>[/code]

–and have modified it in every way I could think of, but cannot manage to get it set up for multiple keys. Obviously I want to link the “a” key to #A and the “b” key to #B and the “c” key to #C and so on, but I can only ever get a single one to work. I’m clumsy and self-taught with javascript and don’t know if it can even be done. Help would be greatly appreciated!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 20.2006 — The code posted, though it will never work at all in NS or FF (for example), is only written to handle a single hotkey at a time. That is why you can only get one to work at a time. Do you have code showing how you propose to handle multiple hotkeys?
×

Success!

Help @blackberry-chan 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.19,
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,
)...