Hey guys, having a bit of a problem with validating some really basic strict html forms. Below (in the code tags) are the validators comments.

character data is not allowed here

<option value="d" />d/ Talking</option>


end tag for element "option" which is not open

<option value="d" />d/ Talking</option>

Then a lot of parsing errors. Someone mentioned something about fieldset or something ? but i haven't included and dont know what that is. Its just a really simple form radio buttons, dropdown box, checkbox and a text box. Help would be really appreciated.

Dani AI

Generated

The validator messages in this thread match what experienced: a start tag that was written as if it were empty made the parser treat the element as self-closed, so the following text and the explicit end tag looked out of place. spotted that and the form validated afterward.

Why that happens: in XML/XHTML an element written as an empty element is considered closed immediately. Any character data that appears after a self-closed start tag will produce errors like "character data is not allowed here" and a mismatched end-tag error. That is why select/option markup must be properly opened and closed and why empty elements (inputs, br, img, etc.) are the only ones that may be self-closed.

Quick checklist for valid XHTML forms (common pitfalls):

  • Keep tags and attribute names lowercase and quote attribute values.
  • Only self-close truly empty elements; normal container elements must have matching end tags.
  • Escape special characters in visible text (use &amp; for &, etc.).
  • Boolean attributes in XHTML must be written with a value (for example, the checked/disabled attributes use an explicit value).
  • Ensure select contains only option or optgroup children and that form elements are not nested.
  • If you use fieldset, legend should be the first child of fieldset.

Practical debugging steps: validate the isolated form snippet with the W3C Validator to get the exact error location, tidy up indentation so mismatches are visible, and fix one error at a time. Refer to the element reference for correct element content models when in doubt (example: the option element documentation on MDN is helpful: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option). For strict XHTML rules, see the W3C XHTML guide: https://www.w3.org/TR/xhtml1/.

Recommended Answers

All 2 Replies

Hey beforetheyknew,

Try omitting the "/" in the opening tag:

<option value="d">d/ Talking</option>

If that doesn't fix your problem, post the code for the entire form (beginning with <form> and ending with </form> ) and we'll break it down from there.

lol thanks a lot man, didn't see that, just needed another set of eyes. I kept lookin at the slash there: 'd/'. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.