Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  116] [ 7]  / answers: 1 / hits: 30781  / 12 Years ago, sun, december 30, 2012, 12:00:00

So in normal situation where jquery i allowed and i can bind the field onkeyup i would use:



$('#something').keyup(function(e) {
var enterKey = 13;
if (e.which == enterKey){
somefunction();
}
});


however i cannot use this and will have to use something like:



<input id=something onkeyup=onkeyup_colfield_check(this) type=text>


 function onkeyup_colfield_check(e){
var enterKey = 13;
if (e.which == enterKey){
somefunction();
}
}


However this doesn't work like the above.



how can i achieve the same result like the first example but with something like that?


More From » html

 Answers
8

You need to pass in event as an argument, not this.



<input id=something onkeyup=onkeyup_colfield_check(event) type=text>


Also, to be fully compatible with all major browsers, you may want to use the following for detecting te key code of the key pressed.



var charCode = (typeof e.which === number) ? e.which : e.keyCode;

[#81168] Thursday, December 27, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
benitoh

Total Points: 150
Total Questions: 113
Total Answers: 104

Location: India
Member since Wed, Aug 26, 2020
4 Years ago
benitoh questions
Sun, Mar 21, 21, 00:00, 3 Years ago
Mon, May 13, 19, 00:00, 5 Years ago
;