Radio Button Validation2. Defining the Buttons |
|
Join the DiscussionMore of this FeatureThe first thing that we need to look at doing when using radio buttons on our form is to look at how the buttons need to be coded in order for them to function properly as radio buttons. We want it so that when one button is selected then whichever button was previously selected is automatically unselected. The solution here is to give all of the radio buttons within the group the same name but different values. Here is the code used to code just radio button themselves on the previous page that shows you how this is done.
<input type="radio"
name="group1" id="r1"
value="1" />
<input type="radio" name="group1" id="r2" value="2" /> <input type="radio" name="group1" id="r3" value="3" /> The creation of multiple groups of radio buttons for the one form is also straightforward. All you need to do is to provide the second group of radio buttons with a different name to that used for the first group. The name field determines which group that a particular button belongs to. The value that will be passed for a specific group when the form is submitted will be the value of the button within the group that is selected at the time that the form is submitted. So now we know how to group radio buttons. The next step is to look at how to attach a description to each button. |

