Keypress

H

Hamish

I am trying to detect the up and down keys on a key press function, but they
do not seem to generate a keypress call. Is there another event generated
when these keys are pressed

Thanks.

PS Apologies if this appears as a double post, but the news server I used
originally does not seem to propagate most other news servers.
 
M

McKirahan

Hamish said:
I am trying to detect the up and down keys on a key press function, but they
do not seem to generate a keypress call. Is there another event generated
when these keys are pressed

Thanks.

PS Apologies if this appears as a double post, but the news server I used
originally does not seem to propagate most other news servers.


Will this help?

http://cita.rehab.uiuc.edu/courses/2003-02-REHAB711NC/lec11/slide14.html

<html>
<head>
<title>onkeys.htm</title>
<script type="text/javascript">
function onkey(what) {
if (what == "") {
window.status = "";
document.forms[0].txt.focus();
} else {
window.status += what + " ";
}
}
</script>
</head>
<body onload="onkey('')">
<form>
<input type="text" name="txt"
size="1" maxlength="1"
onkeypress="onkey('onkeypress')"
onkeydown="onkey('onkeydown')"
onkeyup="onkey('onkeyup')">
<input type="button" name="but"
value="Clear" onclick="onkey('')">
</form>
</body>
</html>
 
J

J. J. Cale

Hamish said:
I am trying to detect the up and down keys on a key press function, but they
do not seem to generate a keypress call. Is there another event generated
when these keys are pressed

document.onkeypress will return your basic functional text keyboard. When
you press an alphanumeric key you will get it's lower case value. When you
press shift and an alphanumeric key you get the upper case value or in the
case of numbers the corresponding shifted characters. If you need to trap
other key events like the up/down arrows or the backspace etc you need
onmousedown or onmouseup and the correct browser feature detection since
there is no standard for DOM Level 2 AIUII. Hope this link helps.
<http://www.javascriptkit.com/dhtmltutors/domeventp2-2.shtml>

Jimbo
 
J

J. J. Cale

J. J. Cale said:
document.onkeypress will return your basic functional text keyboard. When
you press an alphanumeric key you will get it's lower case value. When you
press shift and an alphanumeric key you get the upper case value or in the
case of numbers the corresponding shifted characters. If you need to trap
other key events like the up/down arrows or the backspace etc you need
onmousedown or onmouseup and the correct browser feature detection since
there is no standard for DOM Level 2 AIUII. Hope this link helps.
<http://www.javascriptkit.com/dhtmltutors/domeventp2-2.shtml>

Jimbo

Sorry I meant onkeydown and onkeyup of course :>)
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top