Radio buttons are one way to allow the users of your form to select a single item from a list of items. Radio buttons have a name and value attribute. When more than one radio button has the same name, they form a set from which only one may be selected. You can see this in action in the example above. When you select one, any other one that you have selected becomes unselected. When the form is submitted, the value of the selected radio button will be the value submitted for the name of that group of radio buttons. If you want to have one radio button pre-selected by default use the attribute/value pair; checked="checked"
<form>
<input type="radio" name="a" value="1">
<input type="radio" name="a" value="2">
<input type="radio" name="a" value="3" checked="checked">
</form>
Here is the source code for the HTML of the example on the top of this page:
<table border="1" bgcolor="#aaaaff">
<tr>
<td bgcolor="aaaaff" width="20">
<input type="radio" name="form_bg" value="aaaaff">
</td>
<td>#aaaaff</td>
</tr>
<tr>
<td bgcolor="aaffaa" width="20">
<input type="radio" name="form_bg" value="aaffaa">
</td>
<td>#aaffaa</td>
</tr>
<tr>
<td bgcolor="aaffff" width="20">
<input type="radio" name="form_bg" value="aaffff">
</td>
<td>#aaffff</td>
</tr>
<tr>
<td bgcolor="ffaaaa" width="20">
<input type="radio" name="form_bg" value="ffaaaa">
</td>
<td>#ffaaaa</td>
</tr>
<tr>
<td bgcolor="ffaaff" width="20">
<input type="radio" name="form_bg" value="ffaaff">
</td>
<td>#ffaaff</td>
</tr>
<tr>
<td bgcolor="ffffaa" width="20">
<input type="radio" name="form_bg" value="ffffaa">
</td>
<td>#ffffaa</td>
</tr>>
<tr>
<td align="center" colspan="2">
<input type="submit"></td>
</tr>
</table>
The source code above is the HTML not the PHP that creates the HTML and processes the form. PHP students can get an explanation of the PHP end of the form here
Checkboxes are similar to radio buttons. Supposedly you can give a list of them the same name and all the values will be assigned to the one name but on my tests on both webtv and computer, only the last value was assigned. Instead give them all different names. If you want to have a checkbox pre-checked by default use the attribute/value pair; checked="checked"
|
|
|