1) the only tags that <select>
can have are <option>
and <optgroup>
tags
the validator is complaining because <script>
is not one of those things -- the browser is doing its best to take your invalid markup and turn it into something valid, so despite the fact that it works, that's why you get the error, if you're actually putting <script>
tags inside of a <select>
2) your script tags should be at the bottom of your page, and instead of using document.write
to put option tags there, use DOM methods to add options to the select element after the fact
<select name="select-box"></select>
<!-- ...rest of page... -->
<script src="external-script.js"></script>
/* contents of external-script.js */
var select_box = document.querySelector("select[name=select-box]"),
bob_opt = document.createElement("option"),
doug_opt = document.createElement("option");
bob_opt.value = "Bob";
doug_opt.value = "Doug";
bob_opt.appendChild(document.createTextNode("Bob"));
doug_opt.appendChild(document.createTextNode("Doug"));
select_box.appendChild(bob_opt);
select_box.appendChild(doug_opt);
There are faster and neater, or more-elaborate or more flexible ways of doing this, but this is closer to the "right way" than something like:
<select>
<script>document.write("<option value=\"" + i + "\">one</option>");</script>
</select>
Or whatever you might currently have there.
JS is not meant to be templated like that, without using/writing a templating library for that purpose.