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?
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?
Share Improve this question edited Dec 30, 2012 at 2:37 jeremy 10.1k4 gold badges40 silver badges60 bronze badges asked Dec 30, 2012 at 2:21 Neta MetaNeta Meta 4,04710 gold badges47 silver badges71 bronze badges 2- Why can't you use jQuery ? – Popnoodles Commented Dec 30, 2012 at 2:29
- cannot use in what i am doing right now. jquery is not yet loaded at this stage – Neta Meta Commented Dec 30, 2012 at 2:32
1 Answer
Reset to default 15You 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;