15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

350<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Note<br />

Figure 8-1: Clicking on button choices reveals additional relevant choices<br />

Notice how the toggle() function was written as a generalizable function. This<br />

function can accept a reference to any checkbox object and any related span. If five<br />

more groups like this were added to the table, no additional functions would be<br />

needed.<br />

In the swap() function, an application of a nested if...else shortcut construction<br />

is used to convert the Boolean values of the checked property to the strings<br />

needed for the display style property. The nesting is used to allow a single statement<br />

to take care of two conditions: the group of buttons to be controlled and the<br />

checked property of the button invoking the function. This function is not generalizable,<br />

because it contains explicit references to objects in the document. The<br />

swap() function can be made generalizable, but due to the special relationships<br />

between pairs of span elements (meaning one has to be hidden while the other displayed<br />

in its place), the function would require more parameters to fill in the blanks<br />

where explicit references are needed.<br />

A rendering bug in NN6 causes the form controls in the lower right frame to lose<br />

their settings when the elements have their display style property set to none.<br />

The problem is related to the inclusion of P or similar block elements inside a<br />

table cell that contains controls. Therefore, if you uncheck and recheck the<br />

Communications checkbox in the example page, the previously displayed subgroup<br />

shows up even though no radio buttons are selected. You can script around<br />

this bug by preserving radio button settings in a global variable as you hide the<br />

group, and restoring the settings when you show the group again.<br />

document.formObject.checkboxObject.onClick

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

Saved successfully!

Ooh no, something went wrong!