sure, create a map of keycodes that link keycodes to the target element, then use a loop. Or use object key/value pairs. Here's a sample for two of them:
var keys = {
97: "#.ctl00_ContentPlaceHolder1_rptrQuizQuestions_ctl00_lbAnswers",
49: "#.ctl00_ContentPlaceHolder1_rptrQuizQuestions_ctl00_lbAnswers"
}
$(document).keydown(function (e) {
if ($(e.target).is('input') || $(".answerbtns").length != 0 ) { return }
/* keyboard 1 */
if (keys[e.keyCode]) {
$(keys[e.keyCode])[0].click();
e.stopPropagation();
return false;
}
});
And, if they all have the class "answerbtns", you can do this:
var numeric = [97,98,99,100,101,102,103];
var numpad = [49,50,51,52,53,54,55];
$(document).keydown(function (e) {
if ($(e.target).is('input') || $(".answerbtns").length == 0 ) { return }
/* keyboard 1 */
var index = $.inArray(e.which,numeric);
if ( index == -1 ) {
index = $.inArray(e.which,numpad);
}
if ( index != -1 ) {
$(".answerbtns")[index].click();
e.stopPropagation();
return false;
}
});