Checkbox Fields

The checkbox field is another field type that you define using the input tag.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
<h1>Checkbox Fields</h1>
<form action="#">
<input type="checkbox" id="check" name="check" value="agreed" >
<label for="check">I Agree</label>

Here's what the Checkbox Form page looks like in your web browser.

Again we use a label tag to define the label that is to be associated with our checkbox field only checkboxes usually have the associated text following the form field instead of preceding it. Again we use an input tag to define the actual field.

What we have done is to change the type to checkbox. Specifying a field type of checkbox displays a small square box that can either be checked or unchecked.

We can have our checkbox display as checked to begin with when the page is first displayed by adding the checked="checked" attribute (which must always be assigned the same value in order to meet the XHTML validation requirements).

The value defined for a checkbox field cannot be changed by the person filling out the form. The checkbox field will only be submitted with the rest of the form fields if it is checked (we can make a small change to our form so that each checkbox always passes a value if we want to though).


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow