HTML TextArea can’t be a self closing tab

Hi all!!

Recently, I have been asked to modify the dynamically generated web page I worked on in order to have it generating TextAreas together with Inputs.

The web page meta information is stored into an XML. The back-end uses E4X Javascript as a serverside language so storing the page definition into an XML document was the natural choice.
Having said that, I eventually had to change my JS code in order to store a TextView into this XML in a way similar to this:

myXML.myTextArea = <textarea rows="20" cols="10">

Afterwards my code would do this to render the textArea:

<%== myXML.myTextArea %>

Well.. pretty straightforward, right?

The problem is that this code would generate the following HTML:

<textArea cols="10" rows="10"/>

Unfortunately the HTML above doesn’t work since most of the browsers will interpret a self closing TextArea as an open tag (roughly). Apparently this is a bug at least in Chrome and Firefox and I’ve been able to reproduce it in IE9 as well.

This is how such a TextArea would look like:

How self closing textArea looks.

Self closing textArea

 

The (all but orthodox) way I’ve managed to solve this is this (don’t laugh, please :) :

<%== myXML.myTextArea.toXMLString().replace("/>", "></textArea>") %>

So, whenever you have to use a textArea (either generated from an XML as in my case, or manually written) don’t forget:
TextArea can’t be a self closing tab (at least for now).

Nico


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>