Reputation: 91
I want to auto change input's val and trigger its onkeyup event.
Error: e.which is undefined
<input type="text" id="x">
JS
$("#x").keyup(function(e){ console.debug(e.which); });
I tried
$("#x").val('m').keyup();
$("#x").val('m').trigger("keyup");
$("#x").val('m').trigger("keypress", [35]);
How can I change val and trigger just keyup function? I need e.which.
Edit: if i write manuel to input, i can get debug result (which)
Upvotes: 0
Views: 3151
Reputation: 1330
How about this: (just change the value of letterToUse
each time)
var letterToUse = "A";
var e = $.Event("keyup");
e.which=e.keyCode=letterToUse.charCodeAt();
$("#x").val(letterToUse).trigger(e);
Upvotes: 2