Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am creating a form. It has a few labels, inputs and a submit button.
Should I place the button inside the same fieldset as the inputs and
labels? Or in a different fieldset?

Or maybe I should use the following approach:

1. If the form has only one fieldset then the submit button would be
inside the same fieldset has the inputs and labels.
2. If the form has more than one fieldset then the button to submit
the entire form would be placed in a new fieldset.

This is just an idea.

What is the best approach?


Re: Fieldset

Scripsit shapper:

Quoted text here. Click to load it

On the practical side, it does not matter much.

The fieldset element is, in principle, an element for logical grouping.
Typically, you wrap a set of radio buttons and their labels inside a
fieldset, when they "work together", specifying a "one-of-many" choice.
Or you could use a fieldset that contains fields for a person's name
(e.g., surname, first name, middle name) and their labels; the fieldset
corresponds then to the concept "a person's name". However, such logical
grouping does not matter much to browsers, except for special rendering
of the entire fieldset. This is somewhat unfortunate, since you don't
always want that rendering, and it is difficult to kill it.

Moreover, a fieldset element must have a legend element. Often it is
easy and natural to write one, but not always. (However,
<legend></legend> can be used; it is valid, even if it does not sound
very logical.)

So I would group labels and inputs if they are logically related, and I
would not put a submit button there. I would use just <div><input
type="submit" ...></div>.

Quoted text here. Click to load it

It sounds a bit illogical, and the rendering might be somewhat
misleading to people who are already used to seeing fieldset display for
interrelated fields.

Quoted text here. Click to load it

No reason to put the button in a fieldset, and there would be no natural
legend for it. _If_ you had several submit buttons (which is usually a
bad idea for certain practical reasons), then they might be grouped into
a fieldset, with e.g. <legend>Submit</legend>.

Jukka K. Korpela ("Yucca")

Re: Fieldset

Quoted text here. Click to load it

I use fieldsets since I might have grouping in my forms and I think
fieldset is a good way to do that ... If i don't want to display a
legend I can always do:

fieldset legend {display: none;}

But I think the grouping is useful in some cases.

In relation to the buttons, that was what I was thinking: to place a
div INSIDE the form to contain the buttons ...

Wrapping the buttons in a fieldset, even if more than one (for example
Submit and Cancel), does not make much sense to me ...


Site Timeline