<input type="checkbox">
Browser |
|
---|---|
Type |
The INPUT element defines an input field. When you specify "checkbox" for the type attribute of this element, a checkbox is created.
<input type="checkbox" name="example" value="check1">Check1
<input type="checkbox" name="example" value="check2" checked>Check2
Attribute | Value | Explanation |
---|---|---|
type=" " | checkbox | the type of input field |
name=" " | field name | a unique name for the field |
value=" " | initial value | this value is submitted |
checked | checked | that checkbox is checked (HTML : checked | XHTML : checked="checked") |
- type="checkbox"
- Creates a checkbox on the form.
- name=""
- The field name is used to identify the form field. Several checkboxes can share the same field name, and the plural can be selected within that.
- value=""
- This value is submitted to the server when selected.
- checked
- That checkbox is checked in the initial state.
Example
<form method="POST" action="example.cgi">
<p>
Do you agree? :
<input type="checkbox" name="agree" value="yes">Yes
</p>
</form>
- Output
This form cannot submit because of a sample.
<form method="POST" action="example.cgi">
<p>
What's your favorite animal? :
<input type="checkbox" name="animal" value="dog">Dog
<input type="checkbox" name="animal" value="cat" checked>Cat
<input type="checkbox" name="animal" value="bird">Bird
<input type="checkbox" name="animal" value="fish">Fish
<input type="checkbox" name="animal" value="bear" checked>Bear
</p>
</form>
- Output
This form cannot submit because of a sample.