tags:

views:

1425

answers:

6

This is the code I have that HTML Validator is giving me an error on:

<input type="text" id="search" name="keywords" /> <input type="submit" value="Search" name="Submit" />

Here is a screen shot of error in HTML Validator: http://i39.tinypic.com/mw2m92.png

This is the error message I am receiving:

The mentioned element is not allowed to appear in the context in which you've placed it; the other mentioned elements are the only ones that are both allowed there and can contain the element mentioned. This might mean that you need a containing element, or possibly that you've forgotten to close a previous element.

There are 2 types of elements in the body of a HTML file, inline and block elements. One possible cause for this message is that you have attempted to put a block-level element (such as "<p>" or "<table>") inside an inline element (such as "<a>", "<span>", or "<font>").

In the following sample, the <font> tag is an inline tag which can only contain other inline tags. But the <p> tag is a block tag. So a <p> tag can not be contained in a <font> tag.

This is the block of html that it is from:

<li>
    <form method="post" action="http://site.com/"  >
    <div class='hiddenFields'>
     <input type="hidden" name="ACT" value="19" />
     <input type="hidden" name="XID" value="90ee0994104d8ba87b6ef9b43e998fc8c89e0d9f" />
     <input type="hidden" name="RP" value="search/results" />
     <input type="hidden" name="NRP" value="" />
     <input type="hidden" name="RES" value="" />
     <input type="hidden" name="status" value="" />
     <input type="hidden" name="weblog" value="forms|alumni_distinguished|housing_faq|international_faq" />
     <input type="hidden" name="search_in" value="everywhere" />
     <input type="hidden" name="where" value="all" />
     <input type="hidden" name="site_id" value="1" />
    </div>

    <input type="text" id="search" name="keywords" /> <input type="submit" value="Search" name="Submit" />
    </form>
</li>
A: 

I believe the problem is that the inputs are in a <li> element, which by default is not a block-level element. This is usually the cause of such 'out-of-context' errors. It won't hurt your page at all, but just keep it from validating.

tj111
really ? I've always thought that li is a block level element.
andyk
+1  A: 

You haven't mentioned which HTML verion this validator validates against. Assuming that it is not XTHML, The input tag is not to be closed. The use of the "/>" implies that you are supplying a closing tag.

For more information : Reference

However, this restriction would not hold for XHTML which requires that all tags be closed. (or maybe I should say that the restriction that all tags should be closed applies only in XHTML) ;-)

Cerebrus
In XHTML, it is used for tags that do not require a closing tag (img, input, etc).
tj111
Yes, I added that note as an afterthought.
Cerebrus
A: 

Are you using HTML or XHTML

In HTML the <input> tag has no end tag.

In XHTML the <input> tag must be properly closed.

http://www.w3schools.com/tags/tag_input.asp

geowa4
A: 

Is there an unclosed inline element before the code you supplied? List of inline elements: http://htmlhelp.com/reference/html40/inline.html (for html4)

Spikolynn
+2  A: 

In HTML4 / XHTML1, you can't put inline content directly into a form element. HTML5, on the other hand, lifts that requirement.

Thus, if the validation error bothers you (there are worse things...), add a p or div element around the last two inputs.

Ms2ger
Surprised this didn't get upvoted. This IS the correct answer. Inline elements are not allowed inside forms. So just enclose the input in a div to make validator happy.
Developer Art
Another point is that tables are allowed directly inside of a form. Since table make neither block-level nor inline elements, the validator obviously can't say "no" for sure.
Developer Art
A: 

eg. [code]

[/code]

wrap the input tag within a

tag

and be sure to self close the input tag like above.

This should validate.

Mark