Friday, January 3, 2014

Forms >> HTML Check Box Tag - (PART_32)

Topic

How to create a checkbox in html?
How to make check box pre selected?
How to disable check box?


Explanation

Check Box

Example Code:
<form name=myform>
<input type="checkbox" name=mybox value="1">one
<input type="checkbox" name=mybox value="2">two
<input type="checkbox" name=mybox value="3">three
</form>


Result:
one two three

Definition:
Here we define the check box using "input" tag. We give a attribute called "TYPE=checkbox" in the tag which defines the type as a checkbox.
The attribute "name" should be defined and be same.
The value in this case will be used only during form processing.

Pre selected Checkbox
We can make a check box pre selected (checked) even before the users try to select, using the entry "checked"

Example Code:
<form name=myform>
<input type="checkbox" name=mybox value="1" checked>one
<input type="checkbox" name=mybox value="2" >two
<input type="checkbox" name=mybox value="3" checked>three
</form>


Result:
one two three

Non Editable / Non Selectable check box
We can make a Checkbox non selectable (disable) using the entry "disabled"

Example:
<form name=myform>
<input type="checkbox" name=mybox value="1" disabled>one
<input type="checkbox" name=mybox value="2" disabled>two
<input type="checkbox" name=mybox value="3" disabled>three
</form>


Result:
one two three