The < FIELDSET > and <LEGEND> ElementsThe <FIELDSET> and <LEGEND> elements enable you to format the appearance of elements in a form, and because you use them with forms, I'll discuss them in this chapter. The <FIELDSET> element draws a rectangle around the form, and a <LEGEND> element nested in that <FIELDSET> element enables you to give the <FIELDSET> element a caption, or legend. You can see the properties of these elements in Table 12.13note that the properties, methods , and events we saw in Chapters 5 and 6 also apply to these elements. Table 12.14 lists the additional events of <LEGEND> elements. Table 12.13. The Properties of the <FIELDSET> and <LEGEND> Elements (See Chapters 5 and 6 for the JavaScript core HTML properties, methods, and events that also apply to this element.)
Table 12.14. The Events of the <LEGEND> Element (See Chapters 5 and 6 for the JavaScript core HTML properties, methods, and events that also apply to this element.)
Here's an example for use in the Internet Explorer that enables you to set the align property of a <LEGEND> element on-the-fly by clicking a button marked Right, Left, or Center: (Listing 12-16.html on the web site)<HTML> <HEAD> <TITLE> Using <FIELDSET>, <LEGEND>, And <LABEL> </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function left() { document.getElementById("legend1").align = "left" } function center() { document.getElementById("legend1").align = "center" } function right() { document.getElementById("legend1").align = "right" } // --> </SCRIPT> </HEAD> <BODY> <H1>Using <FIELDSET>, <LEGEND>, And <LABEL></H1> <FORM> <FIELDSET> <LEGEND ID="legend1" ACCESSKEY="L" TABINDEX="1" ALIGN="right">Answers</ LEGEND> <LABEL ACCESSKEY="Y"> <INPUT TYPE="RADIO" NAME="ANSWER" VALUE="YES">Yes </LABEL> <BR> <LABEL ACCESSKEY="N"> <INPUT TYPE="RADIO" NAME="ANSWER" VALUE="NO">No </LABEL> </FIELDSET> <BUTTON VALUE="Right" ONCLICK="right()">Right</BUTTON> <BUTTON VALUE="Left" ONCLICK="center()">Center</BUTTON> <BUTTON VALUE="Right" ONCLICK="left()">Left</BUTTON> </FORM> </BODY> </HTML> You can see this example at work in Figure 12.10, where I've clicked the Right button to realign the legend Answers to the right. (The default is to align to the left.) Figure 12.10. Setting the alignment of a <LEGEND> element.
That finishes our work with buttons, check boxes, radio buttons , fieldsets , and legends in this chapter. We've gotten our start with HTML controlsin the next chapter, we'll build on that when we take a look at the HTML text-based and select controls. |