When you type 2
on your Keyboard, and not on the Number Pad, this represents ASCII character 50
. When you hit 2
on the keypad, with NUM LOCK on, this is ASCII character 98
; w/o NUM LOCK, it's 40
which is mapped to the Down Arrow.
Working Example of this: https://jsfiddle.net/Twisty/uthohe3y/1/
To fix this, you will want to map an event to either KeyDown, KeyUp, or KeyPress events. Would look something like:
$(document).keypress(function(e){
console.log("Key '" + e.key + "' pressed, Character Code: " + e.which);
});
We will need to then do something with this. I suspect you want the corresponding option selected.
Here is one way to do this: https://jsfiddle.net/Twisty/uthohe3y/3/
$(function() {
$("#number").selectmenu().selectmenu("menuWidget").addClass("overflow");
$(document).keyup(function(e) {
var key = e.key;
$("#keyInfo").html("Key : " + key + " (" + e.which + ")");
if ($("[id*='-button']").is(":focus") && (parseInt(key) < 10)) {
e.preventDefault();
if ($("#number option:contains('" + key + "')").length) {
$("#number").val(key);
}
$("#number").selectmenu("refresh");
} else {
return true;
}
});
});
Kudos to: Set a jQuery UI selectmenu to a specific option by javascript