Skip to Main Content
Adobe® Dreamweaver® CS4 Bible
book

Adobe® Dreamweaver® CS4 Bible

by Joseph Lowery
March 2009
Beginner to intermediate content levelBeginner to intermediate
1321 pages
46h 24m
English
Wiley
Content preview from Adobe® Dreamweaver® CS4 Bible
22
I
Creating and Using Objects
Radio buttons
Radio buttons offer a group of options from which the user can select only one. The group is com-
posed of <input type=radio> tags with the same name attribute; the group can contain as few as
two or as many as necessary.
The input type radio, like checkbox, makes use of the checked property to see which option was
selected. The method used to figure out which of the radio buttons was chosen depends on the num-
ber of buttons used on the form:
With just two or three buttons, you may want to use a simple if-else construct to determine
which radio button was selected.
If you are offering many options, you can use a loop structure to look at the
checked prop-
erty of each radio button.
With only a couple of radio buttons in a group, you can examine the one radio-type item in the
array (starting with 0) to see if it was checked. In the following code, if one radio button is selected,
the variable (theChoice) is set to one value; otherwise, it is set to the other value:
if (document.forms[0].comm[0].checked == “1”)
theChoice = “left”;
else
theChoice = “right”;
When you have many radio buttons, or you don’t know how many radio buttons you might have,
use a counter loop such as the one shown in this next example from the Enhanced LineBreak object:
for (var i = 0; i < document.theForm.lbreak.length; i++) {
if (document.theForm.lbreak[i].checked) ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Adobe® Dreamweaver® CS5 Bible

Adobe® Dreamweaver® CS5 Bible

Joseph W. Lowery
Dreamweaver® CS3 Bible

Dreamweaver® CS3 Bible

Joseph W. Lowery

Publisher Resources

ISBN: 9780470382523Purchase book