...

View Full Version : Hot Key on Radio Button?



hawkeyefan
06-23-2009, 08:11 PM
Is there any way to setup a hotkey on a radio button?

For instance I have four radio buttons...

o 1 o 2 o 3 o 4


Is there a way to set up if i press 1 then the first radio will be selected, then it can go to the next set of radio buttons.

Thanks

Philip M
06-23-2009, 08:27 PM
Not really. You would need to enter "1" and so on into form field.


<form name = "myform">

ONE <input type = "radio" name = "rad1">
TWO <input type = "radio" name = "rad1">
THREE <input type = "radio" name = "rad1">
FOUR<input type = "radio" name = "rad1">
<br>
<br>
<input type = "text" name= "box1" size = "1" maxlengh = "1" onblur = "go()">
</form>

<script type = "text/javascript">
function go() {
var x = parseInt(document.myform.box1.value);
if (x >=1 && x <=4) {
document.myform.rad1[x-1].checked = true;
}
}

</script>

hawkeyefan
06-23-2009, 09:35 PM
Is there anyway to set it up without using a textbox to type in the number?

Philip M
06-23-2009, 09:46 PM
Is there anyway to set it up without using a textbox to type in the number?

Nope. You could capture a keypress anywhere within the document with onkeydown() but that would mean that the user would be unable to type in the keys 1-4 without triggering the radio group check.

hawkeyefan
06-23-2009, 09:56 PM
Nope. You could capture a keypress anywhere within the document with onkeydown() but that would mean that the user would be unable to type in the keys 1-4 without triggering the radio group check.

Yeah that is what I am going for, but I want to have about 4 rows of buttons, so its not like I could select the first set of radio buttons use 1-4 and then goto the next set of radio buttons and then do 1-4.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum