Forum Moderators: open

Message Too Old, No Replies

Which should come first, fieldset or form element?

Understanding proper structure of a form...

         

JAB Creations

2:08 am on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which should or could be considered the element to come before the other? The fieldset element allows authors to group thematically related controls and labels while the FORM element acts as a container for controls as W3C specifies. This doesn't clarify how they should be used in conjunction though. Thoughts?

iamlost

5:03 am on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I should think a chapter title answers the question:

17.10 Adding structure to forms: the FIELDSET and LEGEND elements [w3.org]

A fieldset is used to group thematically related controls and labels within a form.

Also:
[w3.org ]


The FORM element acts as a container for controls. It specifies:

* The layout of the form (given by the contents of the element).
* The program that will handle the completed and submitted form (the action attribute). The receiving program must be able to parse name/value pairs in order to make use of them.
* The method by which user data will be sent to the server (the method attribute).
* A character encoding that must be accepted by the server in order to handle this form (the accept-charset attribute). User agents may advise the user of the value of the accept-charset attribute and/or restrict the user's ability to enter unrecognized characters.

A form can contain text and markup (paragraphs, lists, etc.) in addition to form controls.

What do you expect controls outside of a form to accomplish?

I know that a fieldset alone validates but as it is the form that includes the mechanism for data submission that is of no practical importance.

My summary to answer your question: A form may but does not have to include a fieldset; a fieldset must be enclosed within a form for its controls to work.

D_Blackwell

5:07 am on Dec 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fieldsets are used to group form controls that would naturally be considered part of a set. 'Billing' might have a group of inputs enclosed by a fieldset, where 'Shipping' might be another group of fields enclosed by a fieldset.

<edit>iamlost - iamslow:))</edit>