View Full Version : capture keypress

10-30-2006, 07:03 PM
Hi Guys,

I'm trying to capture a keypress, and in particular looking for the cursor up and cursor down key stroke.

I have a hyperlink (with a value of 0) and when the user clicks on it, they should be able to navigate the value up and down using the cursor keys. here's what I have so far

function eg3(ctrl) {
var current = ctrl.innerHTML;
var new_figure = (parseFloat(current) + 1);
ctrl.innerHTML = new_figure;

<a href="#" id="eg3_1" onKeyDown="return eg3(this)">0</a>

it works ok in that when the user clicks it, you can press any key and it increments by one. I need to capture the cursor up and down keys though.

any ideas?! I'm lost!!

10-30-2006, 09:44 PM
You talking about mouse click?

10-31-2006, 10:01 AM
no, i am after capturing the keypress!

all I need to do is capture what key the user has pressed and if it's the cursor key up, increment the value by one... if it's down, then take one off the current value.

I get the keypress, but I cannot seem to find out which key they've pressed!