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?
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With