How old are you?
2
3
4

What do you like best?
monkeys
toys
mommy
With half as much code, no loops with nested if statements, how can this work just like the other?

Hidden fields! You always knew they were good for something, right?

"What do hidden fields have to do with my radio buttons!", you ask? Using a simple expression that sets the value of the hidden field to a radio's own value when it is clicked is the real trick to skipping the extra steps.

Remember, variable values can change, so a user can click as many times as they want, changing the hidden field's value each time. The last radio button to be clicked will be the value of the hidden field.
<input type="hidden" name="ive_got_group1">

<input type="radio" name="group1" value="mommy" onClick="document.form.ive_got_group1.value=this.value">
To do something with the checked button's value, just reference the value of the hidden field(s), using if...else statements to handle errors. Netscape won't clear a hidden field's value using a simple reset button. So to clear the hidden fields' values when the user clicks the reset button, include an onClick event handler that sets the hidden values to an empty string.

View the Source



 


Home | Contact