HTML5, CSS3, and JavaScript Fourth Edition

(Ben Green) #1

CHAPTER 17. FORMS AND INPUTS 178


type=checkbox


<input type=checkbox ...>is the tag for a checkbox. This is generally a
square space in which there is either a checkmark or not.


Normally each checkbox has a different name.


The name and value are transmitted to yourCGIprogram if and only if
the box is checked. Checked? Transmitted. Not checked? Not transmitted.


You can pre-check one or more the spots by using the checked parameter.
checked=checkedor simplycheckedwith no equals sign.


Note thatchecked=anythingprobably works.


Note thatchecked=falsedoes not do what you might think. It acts just the
same aschecked=truebecause the browser just cares whether the checked
attribute is present.


type=radio


<input type=radio ...>is the tag for a radio button. This is generally a
round space in which there is either a dot or not.


Radio buttons are for selecting among mutually exclusive alternatives, like
yes/no, male/female, or ford/honda/toyota/chevy.


Several related radio buttons are grouped together by having the same name.
If one is clicked, the dot moves to that space and is removed from any other
space it may have been in before.


You can pre-select one of the spots by using the checked parameter.checked=checked
or simplycheckedwith no equals sign.


This is pretty much just like the checkbox option above.


Note thatchecked=anythingprobably works.


Note thatchecked=falsedoes not do what you might think. It acts just the
same aschecked=truebecause the browser just cares whether the checked
attribute is present.


type=file


<input type=file ...>is the tag for uploading a file.

Free download pdf