I have a basic quantity field and would like to allow the user to increase/decrease the number within this input box based on the keyboard up/down.
Following on from: EndangeredMassa answer on keyboard code https://stackoverflow.com/a/375426/560287 how would I add this into a keyup function?
var keynum = 0;
if(window.event) { keynum = e.keyCode; } // IE (sucks)
else if(e.which) { keynum = e.which; } // Netscape/Firefox/Opera
if(keynum == 38) { // up
//Move selection up
}
if(keynum == 27) { // down
//Move selection down
}
Here is a demo: http://jsfiddle.net/QRNP8/1/
Note that jQuery normalizes the
charCode/keyCodeproperties intoevent.which:Source: http://api.jquery.com/category/events/event-object/