In our previous article, we discussed how to create tables in HTML and how to add data to them. In this episode we will go over forms and how to collect data from users. We will learn to create text fields, radio buttons, check-boxes, buttons, drop-down menus, and much much more. There is a lot of ground to cover in this one, so let's go ahead and get started.
Radio buttons are used when you want the user to choose from a limited number of choices. They are named from old style radio buttons that you press in. Here is a sample of how they look in code:
<html>
<body>
<form action="">
<p>Are You Fat?</p>
Yes:
<input type="radio" checked="checked"
name="Fat" value="yes">
<br>
No:
<input type="radio"
name="Fat" value="no">
</form>
</body>
</html>
This would display:
Are You Fat?
Note that the type is "radio" and that the "Yes" radio button's checked value is "checked." This means that in the list of buttons, the "Yes" button is checked by default. If the user clicks on the "No" button, the "Yes" becomes unchecked.
You may also notice that both buttons share the same name. If the buttons are to work together, the name value must be the same. Otherwise when you click on one, then another, they will both remain checked.