University of Melbourne home page
 

Boolean checkbox

Use a single checkbox when you want a simple yes/no answer. This is recommended above using radio buttons with yes and no values.

Syntax

The checkbox field is an input of type checkbox. The value attribute is usually output by the form processing script but is not seen by the user. The name attribute is used by the form processing script to label and identify the input text.

<input type="checkbox" name="q4" value="yes" />

Sample

To comply with accessibility guidelines, the field must be explicitly and uniquely identified and labeled, and to work with the template style sheets, some divs, spans and classes must be added.

<div class="boolean">
  <span class="question">A boolean checkbox for simple on/off responses</span>
  <span class="answer"><label for="q4"><input type="checkbox" name="q4" id="q4" />boolean checkbox</label></span>
</div>

Example

A boolean checkbox for simple on/off responses

Validation

To enable validation for this type of field you need to add the required class to the enclosing div and a span of class required-flag to the question span.

<div class="boolean required">
  <span class="question">A boolean checkbox for simple on/off responses <span class="required-flag">(required)</span>:</span>
  <span class="answer"><label for="q4"><input type="checkbox" name="q4" id="q4" />boolean checkbox</label></span>
</div>
 
html/forms/library/boolean.txt · Last modified: 2007/09/11 15:48 by aharris
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki