Welcome to Geoffrey Swift's βlog. Please subscribe to the Atom feed.


Blog is open for comments

The latest feature of my site is one that allows anyone to post a comment against items in my blog. Just like the blog itself, the storage mechanism is an Atom xml file, so there's even a feed.

While writing a template for the comment form in XSL, I found an interesting problem with whitespace normalisation. The XHTML produced originally included a tag like this <textarea/>, rather than <textarea></textarea>. Internet Explorer doesn't recognise XHTML, and so ignores the fact the tag has been closed as per XML rules. The result is that any subsequent HTML is assumed to be the contents of the textarea, and could be clearly seen as such on screen!

I solved a similar problem with script tags, by putting the opening and closing tags on separate lines. But this technique means the form does not initially appear blank, rather the blank line appears in the textarea instead. The solution I adopted was to use the "zero width no-break space" Unicode character, resulting in an apparently blank form:

<textarea> <xsl:text>&#65279;</xsl:text> </textarea>

This all looked fine, until I tried validating the form in DHTML. Although the form appears blank to the user, and does even in "view source", it is not blank! To check for the comment being blank, I stripped out the \uFEFF character in JavaScript first. Internet Explorer's JavaScript implementation at least understands Unicode regular expressions!

The form validation is written generically also, a new script looks for any forms and adds in a new onsubmit event handler. This event handler processes any elements with the attribute class="mandatory", and notifies the user they are blank. The message displayed on screen even makes use of the text in the <label> associated with the form element.

Comments

What is a GCSE? I saw it on your website, mate... what is it? How come you don't have a link explaining it like you do everything else.
The problem mentioned above is no longer relevant. XHTML is now only used internally, there is a final pass of the output to convert it all to HTML 4.

Comments for this post are now closed.