Richard Korts
asked on
Detecting Keypress in Javascript
I wrote a small test to try to capture keyup event.
It doesn't work, see attached code.
What's wrong?
It doesn't work, see attached code.
What's wrong?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Check Key Press</title>
<script type="text/javascript">
document.st.onkeyup = KeyCheck;
function KeyCheck() {
var KeyID = document.st.onkeyup.keyCode;
if (var == 13) {
alert("Enter pressed");
} else {
alert("other key pressed");
}
// -->
</script>
</head>
<body>
<form method="post" name="st">
<input type="text" name="txt" size="3"><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works good, but I still can't understand why it has to be so complex.
>Works good, but I still can't understand why it has to be so complex.
Because it's not the same code for Netscape like and IE navigator.
Because it's not the same code for Netscape like and IE navigator.
Thanks for the points!
Check this link : http://www.w3schools.com/jsref/event_onkeypress.asp
Check this :
Open in new window