15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 8 ✦ Button Objects (Chapter 24)<br />

checked property is true, it returns the value of the index. In one instance, that<br />

index value is used to extract the value property for display in the alert dialog box;<br />

in the other instance, the value helps determine which button in the group is next<br />

in line to have its checked property set to true.<br />

Listing 24-6: Finding the Selected Button in a Radio Group<br />

<br />

<br />

Extracting Highlighted Radio Button<br />

<br />

function getSelectedButton(buttonGroup){<br />

for (var i = 0; i < buttonGroup.length; i++) {<br />

if (buttonGroup[i].checked) {<br />

return i<br />

}<br />

}<br />

return 0<br />

}<br />

function fullName(form) {<br />

var i = getSelectedButton(form.stooges)<br />

alert(“You chose “ + form.stooges[i].value + “.”)<br />

}<br />

function cycle(form) {<br />

var i = getSelectedButton(form.stooges)<br />

if (i+1 == form.stooges.length) {<br />

form.stooges[0].checked = true<br />

} else {<br />

form.stooges[i+1].checked = true<br />

}<br />

}<br />

<br />

<br />

<br />

<br />

Select your favorite Stooge:<br />

Moe<br />

Larry<br />

Curly<br />

Shemp<br />

<br />

<br />

<br />

<br />

<br />

353<br />

document.formObject.radioObject.checked

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!