HTML Checkbox | |
Another type of input is the check box. Check boxes are used when you want users to be able to select more than one of the options. Below is an example:
Code:
<input type="checkbox" name="color" value="red">Red<br>
<input type="checkbox" name="color" value="green">Green<br>
<input type="checkbox" name="color" value="blue">Blue<br>
In this case, the key is color, and the values can be either red, green, or blue, depending on the check box(es) selected. If multiple check boxes are checked, the "color" key will then have multiple values.
If we want to pre-select a check box, we'll specify "checked" at the end of the
<input> tag, such as follows:
<input type="checkbox" name="color" value="red" checked>Red<br>