Hello everyone.
I'm trying to code either the keyup or keypress event for an input field in javascript but can't find any good sample code on how to do it. The example on www.w3schools.com doesn't work for me. Can someone please help me with this?
Printable View
Hello everyone.
I'm trying to code either the keyup or keypress event for an input field in javascript but can't find any good sample code on how to do it. The example on www.w3schools.com doesn't work for me. Can someone please help me with this?
It's pretty basic code. Not sure how W3Schools could mess it up.
Code:<script type="text/javascript">
function chkKey(e) {
if (e.keyCode == 13) {
window.alert("Return key");
}
}
</script>
<input type="text" name="textbox" onkeydown="chkKey(event)">
I replaced the body of the function with a simple alert('test'); just to simplify it some and tested the code in IE and Firefox and it worked just fine. Super thanks my friend.