[sclug] XHTML Question

Roland Turner raz.fpyht.bet.hx at raz.cx
Sat Oct 25 09:05:44 UTC 2003


On Fri, Jun 20, 2003 at 01:01:17AM +0100, Tim Sutton wrote:

> I am trying to make an xhtml compliant page so that I can put the nice little 
> w3c xhtml 'tick' logo at the bottom. Everything in the page is compliant, 
> except in som cases I create an empty select box that get populated by 
> javascript after the page has been loaded through user interaction. So 
> according to the w3c validator both:
> 
> <select>
> </select>
> 
> and 
> 
> <select/>

That is correct. All three versions of the XHTML DTD (Strict[1],
Transitional[2] and Frameset[3]) contain the following line:

    <!ELEMENT select (optgroup|option)+>  <!-- option selector -->

The '+' symbol indicates that the select must contain one or more
optgroup or option children. If it was valid for a select to not
have children (i.e. zero or more children were allowed), the '+'
would instead be a '*'.

> Are not valid. Does anyone have a clever way of including an empty select box 
> and still maintaining a valid xhtml page?

As above, a valid XHTML page will not have empty selects.

This looks to me like one of those cases where the development
environment is drawing your attention to a problem in how you are
trying to proceed.

You haven't told us what you are trying to do, but I'm guessing that
for your page to work correctly, there will need to be something in
that select box. If so, I'd suggest that the basic page contin a
usable default which the Javascript, if it gets the opportunity
to run, will replace with something more closely adapted to
whatever circumstance the Javascript is there to adapt to. (If
your Javascript is not there to adapt the page to some information
unavailable to the server, or information which changes while the
page is displayed, then why is it there at all?)

As for the use/don't-use argument; people tend to move quickly to
extreme, emotionally charged, positions when ordinarily the truth
is somewhere in between. There really are cases where it makes
sense to use Javascript to tweak a web page, but it remains important,
at least for publically accessible pages, to make certain that the
page continues to work when its Javascript cannot. I recommend
neither that you refuse to use Javascript, nor that you go
overboard, rather that you make sure that your page works,
if unattractively, without Javascript and the Javascript
is used only to improve the appearance to/interaction with
those users whose browsers your scripts do end up running on.

- Raz

1: http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd
2: http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
3: http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd



More information about the Sclug mailing list