views:

119

answers:

1

I encounter a problem in my web program. I got a textarea in my form, sometimes there is nothing in textarea, so genshi template engine just output it as

<textarea xxxx />

and here comes the problem, all following tags are in the textarea. Why all browser can't handle single textarea correctly?

If I write it as

<textarea xxxx></textarea>

and everything works fine. Why single textarea mess follow tags in xhtml?

+4  A: 

Because you are, presumably, serving your XHTML with a text/html Content-type and causing it to be processed as HTML. XML style self-closing tags do not exist in HTML (so you have to use explicit start and end tags, except where they are forbidden (e.g. end tags on img) or optional (e.g. start and end tags on the body element).

If you want to have your pages processed as XHTML then serve as application/xhtml+xml (and kiss goodbye to support from Internet Explorer).

(This is why I stick to HTML 4.01 for most projects)

See http://www.w3.org/TR/xhtml-media-types/ for more details (including the full set of compatibility guidelines to munge your XHTML into a shape where HTML user agents can cope with it).

David Dorward
+1 for sticking to HTML 4.01. HTML can be valid too.
Ionuț G. Stan