demosthenes.info

A blog by Dudley Storey on , , , , , , and anything else that strikes his fancy.

featured articles

popular favourites

HTML Forms: Checkboxes

Checkboxes are for questions in which you have a range of possible answers and the correct selection for the user may be from none, all, one or some of them. An example of a question appropriate for checkboxes might be asking the user what ice cream flavours the user likes:

  1. <fieldset>
  2. <legend>What flavors of ice cream do you like?</legend>
  3. <label for=“vanilla” accesskey=“v”>Vanilla</label>
  4. <input type="checkbox" name="vanilla" id=vanilla" />
  5. <label for=“chocolate” accesskey=“c”>Chocolate</label>
  6. <input type="checkbox" name="chocolate" id=chocolate" />
  7. <label for=“strawberry” accesskey=“s”>Strawberry</label>
  8. <input type="checkbox" name="strawberry" id=strawberry" />
  9. </fieldset>

(Note that some of the accesskey shortcuts used above would conflict with the input for “city” made in our text input example.)

A checkbox can be turned “on” or checked by default by adding a checked = “checked” attribute to the tag. Be careful when doing so, however (just as you would be when using the same code with a radio button), as this comes close to “implied content”. (An example of implied consent: the statement “if a woman doesn’t say no, she means yes”.)

web developer guide

featured comment

by JoelB in Goodbye, JQuery Validation: HTML5 Form Errors With CSS3

what i'm reading

A Storm of Swords: A Song of Ice and Fire: Book Three
A Storm of Swords: A Song of Ice and Fire: Book Three

what i'm watching

Californication: The Third Season
Californication: The Third Season

what i'm playing

Mass Effect 3 Collector's Edition
Mass Effect 3 Collector's Edition

what i'm hearing

Dub FX
Dub FX

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.