SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru tictike's Avatar
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    863
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is a fieldset element neccessary on a very short form?

    Being that the form is so short, would you use a fieldset with the following markup? Why, why not?

    Code HTML4Strict:
    <form action="" name="search" id="search">
    	<label for="selKeywords">Product Search</label>
    	<input type="text" name="selKeywords" id="selKeywords" value="" size="20" maxlength="50">
    	<input type="submit" name="btnSubmit" value="Go">
    </form>

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,189
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    It would depend on the context. For example, if it was in the corner of the top bar all by itself, probably not. But if it was with other forms then probably yes. That way I could use the same CSS to style the forms so they looked similar.

  3. #3
    Resident curmudgeon bronze trophy gary.turner's Avatar
    Join Date
    Jan 2009
    Location
    Dallas
    Posts
    990
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tictike View Post
    Being that the form is so short, would you use a fieldset with the following markup? Why, why not?
    Yes, or some other block element, e.g. <p>, or even <div>. The form element may not have an %inline element as a child. See 17.3 The FORM element.

    cheers,

    gary
    Anyone can build a usable website. It takes a graphic
    designer to make it slow, confusing, and painful to use.

    Simple minded html & css demos and tutorials

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In a Strict DTD – which is the recommendation – a form can only contain block-level children, so you'll need to wrap your inline labels and inputs in something. You can use a div, but a fieldset would be more semantically appropriate.
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Evangelist Karpie's Avatar
    Join Date
    Jul 2007
    Location
    Perth, Australia
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use fieldsets on all forms. Habit.

  6. #6
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends on the requirement. I mostly use the field set.

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,834
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You have to use a block level element of some sort for the form to be valid. In most instances a fieldset is a reasonable choice.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  8. #8
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, using a fieldset with a nested legend will aid in accessibility


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •