Frequently Asked Questions
Radio buttons?
-
Radio buttons?
Posted on May 21, 2004
Written by
Louise (view more by Louise)
Filed under FAQ, NL-PHPMail, PHP, Scripts
How can a have one of those check lists where the person can select one answer only (radio buttons)?
Radio buttons allow the user to choose only one of a number of options. When you choose one option, any previously selected option is unselected. Radio buttons are grouped together by assigning them all the same NAME (but different VALUES).
<p>Which one of these old TV Shows do you miss the most? <br /><input type="radio" name="oldtv" value="madaboutyou" />Mad About You <br /><input type="radio" name="oldtv" value="fullhouse" />Full House <br /><input type="radio" name="oldtv" value="stepbystep" />Step by Step <br /><input type="radio" name="oldtv" value="partyof5" />Party of Five <br /><input type="radio" name="oldtv" value="dawsonscreek" />Dawson's Creek <br /><input type="radio" name="oldtv" value="buffy" />Buffy, the Vampire Slayer</p>
Like checkboxes, you can define a radio button to be checked by default, but unlike checkboxes you should only have one radio button in a group initially checked.
<p>Which one of these old TV Shows do you miss the most? <br /><input type="radio" name="oldtv" value="madaboutyou" checked="checked" />Mad About You <br /><input type="radio" name="oldtv" value="fullhouse" />Full House <br /><input type="radio" name="oldtv" value="stepbystep" />Step by Step <br /><input type="radio" name="oldtv" value="partyof5" />Party of Five <br /><input type="radio" name="oldtv" value="dawsonscreek" />Dawson's Creek <br /><input type="radio" name="oldtv" value="buffy" />Buffy, the Vampire Slayer</p>
Now you have Mad About You checked and set as default.
Remember: all the radio buttons in a group must have identical names (like in the example above - the name is set to "oldtv" for each option).