
Originally Posted by
Denk
as Pullo said, use the keypress or keyup action (I've always used the keyup event. Don't ask me why though

) to select the "ok" option (if it's a div, then set a hidden field) and then call upon the submit function of the form.
Yeah, should be pretty much something along those lines.
If you have some basic HTML for your form:
HTML Code:
<form action="?" method="get">
<fieldset id="choices">
<legend>Make a choice</legend>
<p><input type="radio" name="question_1" id="choice_1" value="1"><label for="choice_1">1. Very good</label></p>
<p><input type="radio" name="question_1" id="choice_2" value="2"><label for="choice_2">2. Good</label></p>
<p><input type="radio" name="question_1" id="choice_3" value="3"><label for="choice_3">3. Ok</label></p>
<p><input type="radio" name="question_1" id="choice_4" value="4"><label for="choice_4">4. Poor</label></p>
<p><input type="radio" name="question_1" id="choice_5" value="5"><label for="choice_5">5. Very poor</label></p>
</fieldset>
<fieldset>
<input type="submit" value="Submit" id="btn-submit" />
</fieldset>
</form>
Then the following JavaScript will do exactly what you want 
Code javascript:
$(document).ready(function(){
$("body").on("keyup", function(e) {
var charCode = e.keyCode,
key,
$choices = $("#choices");
if ( (charCode >= 49 && charCode <= 53) || (charCode >= 97 && charCode <= 101) ) {
if (charCode > 96) {
charCode = charCode - 48; //compensate for numpad offset
}
key = String.fromCharCode(charCode);
//set the right item to checked
$("input[value="+key+"]", $choices).attr("checked", "checked");
//submit the form
$choices.closest("form").submit();
}
});
});
Basically, monitors the keyup event on the body, when it is either # 1 - 5 on the std numbers or 1 - 5 on the numpad it will process and convert the keyCode to a character (which will end up being one of 1-5), then it will find the radio button with that value and set it to checked. And of course finally, submit the form.
(Oh and don't forget to include jQuery of course
)
Bookmarks