Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  129] [ 4]  / answers: 1 / hits: 46037  / 15 Years ago, wed, march 3, 2010, 12:00:00

If you replace onkeydown with click, it reacts, at least.



<input id=yourinput type=text />

<script type=text/javascript>
document.getElementById(yourinput).addEventListener(onkeydown, keyDownTextField, false);

function keyDownTextField() {
alert(functional);
if(keycode==13) {
alert(You hit the enter key.);
}
else{
alert(Oh no you didn't.);
}
}
</script>

More From » javascript

 Answers
29

The event type should be keydown, notice that you don't need the on prefix:



element.addEventListener(keydown, keyDownTextField, false);


Note also that you should get the keyCode from the event object in your handler:



function keyDownTextField (e) {
var keyCode = e.keyCode;
//...
}


Check an example here.


[#97439] Saturday, February 27, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryanulyssesb

Total Points: 91
Total Questions: 105
Total Answers: 102

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
ryanulyssesb questions
Sat, Mar 20, 21, 00:00, 3 Years ago
Mon, Sep 14, 20, 00:00, 4 Years ago
Mon, Mar 9, 20, 00:00, 4 Years ago
Sun, Jul 7, 19, 00:00, 5 Years ago
;