views:

416

answers:

2
<form id="youtube-form" method="post" action="">

  <label for="searchField" id="label-youtube-id">YouTube ID:</label>
  <input type="text" id="searchField" name="videoid" class="search-field" />

  <fieldset id="outputFieldset">
    <legend>Output format:</legend>
        <label for="flv">FLV</label>
        <input type="radio" id="flv" name="format" class="radio-button" value="flv" />

        <label for="avi">AVI</label>
        <input type="radio" id="avi" name="format" class="radio-button" value="avi" />

        <label for="mp3">MP3</label>
        <input type="radio" id="mp3" name="format" class="radio-button" value="mp3" />
  </fieldset>

  <input id="youtube-submit" type="submit" name="submit" value="Submit" />

</form>

What is wrong with this code? I seem to get an error when I validate. (three of them too)

Line 21, Column 49: document type does not allow element "label" here; missing one of "ins", "del", "h1", "h2", "h3", "h4", "h5", "h6", "p", "div", "address", "fieldset" start-tag

Is it because I need to add more fieldsets, or is it something else I have done wrong?

Any help is much appreciated :)

A: 

Labels and inputs should be inside the fieldset. Or create a second/third filedset to enclose them separately.

eg:

<form id="youtube-form" method="post" action="">


 <fieldset id="youtube">
  <label for="searchField" id="label-youtube-id">YouTube ID:</label>
  <input type="text" id="searchField" name="videoid" class="search-field" />
 </fieldset>

  <fieldset id="outputFieldset">
    <legend>Output format:</legend>
        <label for="flv">FLV</label>
        <input type="radio" id="flv" name="format" class="radio-button" value="flv" />

        <label for="avi">AVI</label>
        <input type="radio" id="avi" name="format" class="radio-button" value="avi" />

        <label for="mp3">MP3</label>
        <input type="radio" id="mp3" name="format" class="radio-button" value="mp3" />
  </fieldset>

 <fieldset id="submit">
  <input id="youtube-submit" type="submit" name="submit" value="Submit" />
 </fieldset>
</form>
Jon Hadley
Thank you for provided the proper code for me to use. I have learned from this.
MindTooth
A: 

input and label elements are not allowed as child elements to form elements.

ins, del, h1, h2, h3, h4, h5, h6, p, div, address, fieldset are allowed as child elements and are also allowed to have input and label elements as their children (although most are not semantically appropriate).

David Dorward
Thank you :) Now I understand the problem. But why do you see so many guides on the internet omitting the fieldset completely?
MindTooth
Inputs and labels are allowed as child elements of forms in Transitional versions of HTML. We are far past the transitional period now.
David Dorward