Navigate table rows using arrow keys

S

skipc

Hi,

I am stuck... I've got a popup window that displays a list in table
format with links on the bottom to navigate the list <prev> 1 2 3 ...
<next>

When I demo'd to the users... they immediately asked if they could use
the arrow keys and enter key to navigate the list. I think there must
be a way to do this, but I can't figure it out.

Has anyone out there done this? I would like to keep the mouse
navigation but add the ability to navigate using the keyboard.

Thanks! D
 
S

skipc

Tom,
Thanks. That helps. I think I've got all the pieces. I think I have to
figure out which row in the table the user is on, add or decrement and
focus on the new row. I will keep working on it.

-D
 
R

RobG

tom said:
Yes, you can do that...

yo need to capture the key pressed by user, i recommend check this
page, there you can find the way to do that

http://www.geekpedia.com/tutorial138_Get-key-press-event-using-JavaScript.html

That script could be somewhat more compact as:

<script type="text/javascript">

var keys = { 16:'shift', 17:'Ctrl', 18:'Alt', 19:'Pause',
37:'Arrow Left', 38:'Arrow Up', 39:'Arrow Right',
40:'Arrow Down'
}

function KeyCheck( e ) {
var msg = document.getElementById('xx');
var e = e || event ;
msg.innerHTML = keys[e.keyCode] || '';
}

</script>
</head>
<body onkeyup="KeyCheck(event);">
<p>The key you pressed was:
c</p>
</body>


[...]
 
A

ASM

RobG said:
That script could be somewhat more compact as:

<script type="text/javascript">

var keys = { 16:'shift', 17:'Ctrl', 18:'Alt', 19:'Pause',
37:'Arrow Left', 38:'Arrow Up', 39:'Arrow Right',
40:'Arrow Down'
}

Waou ! wonderful !
Is it an array ? object ? whatelse ?
function KeyCheck( e ) {
var msg = document.getElementById('xx');
var e = e || event ;
msg.innerHTML = keys[e.keyCode] || '';

msg.innerHTML = keys[e.keyCode] || e.keyCode;

would be instersting to see some key codes :)
}

</script>
</head>
<body onkeyup="KeyCheck(event);">
<p>The key you pressed was:
c</p>
</body>

document.getElementById('xx') outside with the dog ?
 
R

RobG

ASM said:
Waou ! wonderful !
Is it an array ? object ? whatelse ?

I think it's an object, my browser agrees. ;-)

Another way is:

var keys = new Object();
keys[16] = 'shift';
keys[17] = 'Ctrl';
...

But I like my way 'cos it's much more concise, though sometimes the
longer method is better for maintenance reasons 'cos it's a bit more
readable.

I'm sure there's a French equivalent for 'to each her own'. All I can
think of is 'Que sera sera' which doesn't seem appropriate...

[...]
document.getElementById('xx') outside with the dog ?

If I had a dog it would have died of a persecution complex long ago. it
seems my fingers forgot to type everything my brain told them to.

"I've done my homework, I just haven't written it down yet" :-x
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top