1
votes

Why the select tag need to have at least on child to be valid xhtml 1.0 ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Why select tag need at least one child to be xhtml valid ?</title>
</head>
<body>
Allowed users :<br/>
<select size="5" style="width: 200px">
</select>
<br />
Alls users :<br/>
<select size="5" style="width: 200px">
  <option>root</option>
  <option>John Doe</option>
  <option>Jane Doe</option>
</select>
</body>
</html>

To be valid, I need to write :

<select><option/></select>

I think it's useless and it's cumbersome to add the empty option tag programmatically (especially in ASP.NET WebForms, I use a DropDownList or ListBox control with a dataBind) :

if count == 0 then add <option/>...

There is no explanation in the DTD : http://www.w3.org/TR/xhtml1/dtds.html

Do you know why W3C validation require that ?

(And how can I make this page valid using a DropDownList or ListBox control in ASP.NET WebForms 4.0 ?)

3
Why would you add a select tag without any options is the real question here. :)PeeHaa
For example : a select tab containing all users and a second select tag continaing authorized users (and buttons to allow or deny users)Jonas at Software Journey

3 Answers

1
votes

Assuming that the reason this is an issue is because you are adding the options dynamically, I would suggest that also add the select dynamically, too.

In fact, you could add a node on page load...

<a name="whatever" id="whatever-id" />

and replace it with a select and options when necessary.

0
votes

What would be the semantic meaning of a select without any options? You might as well not have a select...

0
votes

Why? Most likely because its a standard defined approximately 10 years ago. You should consider moving on...

Example below.


HTML5

Switch your doctype line to:

<!DOCTYPE html>

And your meta charset line to:

<meta charset="UTF-8" />

Resulting HTML Markup:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>Why select tag need at least one child to be xhtml valid ?</title>
</head>
<body>
    Hello World : <select></select>
</body>
</html>

Feel free to validate in http://validator.w3.org/#validate_by_input