I need to capture an onkeyup
event on an image element. Here's the markup for that element:
<input class="globalbuttons" type="image" alt="save" title="save"
onclick="resetScrollPosition(); tabindex="0"
src="/kc-dev/kr/static/images/buttonsmall_save.gif"
name="methodToCall.save">
The reason is to force all users to use the mouse and CLICK the button, rather than allow the user to tab into the image and press Space or Enter to emulate a mouse click.
I got the following simple test to work:
<input class="globalbuttons" type="image" alt="save" title="save"
onclick="resetScrollPosition(); tabindex="0"
onkeyup="alert(event.keyCode);"
. . .
The alert properly shows the key codes for every key that I press while the image remains in focus. Next, I tried replacing the alert with a function and passing the function the event, but this was not working.
Also, I'm wondering if this is the best approach:
Should I only ignore the key presses that could "emulate a click" (e.g. Space or Enter) .
OR
Is better to not to discriminate the key that got pressed, but rather ignore ALL keys for this element?
Thanks.