jim.shamlin.com

Checkbox

A clicked renders a special type of button that can be seelcted to indicate a "true" value or deselected to indicate a "false" value.


Basics

Bare-bones code for a checkbox is:

<INPUT TYPE="checkbox">

This renders the checkbox only and not any associated label.


Usage

A single checkbox provides an independent true/false value, and is a natural for binary questions (yes or no). However, they are also commonly used in sets to enable the user to "check all that apply."


Processing

How a checkbox is passed depends on the browser.

All browsers will pass a name=value pair of some kind to the server when the checkbox is checked at the instant the form is submitted, but the value passed is not consistent. It should be the content of the VALUE attribute, but in some instances, it is "true" or "on" or "checked" - but fortunately, it's always non-null value.

If the checkbox is not checked, some browsers will pass a null, others won't pass a name=value pair at all.


HTML Attributes

The checkbox usually has only a name and value, but other attributes are available:

The VALUE for a checkbox is optional - browsers will pass a non-null value if it is not specified. Some browsers will pass a default value even if it is.


JavaScript

Properties

Methods

Event Handlers


Misc Notes

If you need to provide a set of checkboxes and allow the user to check only two of them, a JavaScript hack will be needed.