Forum Moderators: open
I have been getting this error with my select boxes on my form.
What does that error mean and how do I fix it please?
This is my code:
<select name="city" id="city" onfocus="this.style.background='#fff';" onblur="this.style.background='#eee';">
<option>Please select one</option>
<option selected= selected>Ely</option>
<option selected=>Little Downham</option>
</select>
Any suggestions?
I am using PHP to generate:
<?
for ($i=0;$i<sizeof($categories);$i++) {
print "<option";
if ($row['business_category']==$categories[$i])
print " selected";
print ">".$categories[$i]."</option>\n";
}
?> Thanks
Ely<option selected= selected></option>Little Downham<option selected=></option>
It may well be to do with the above snippet, because of your use of of the
selected attribute. You should either be using: <option selected="selected"> (obligatory if you are using XHTML), or:
<option selected> if you are using HTML4.
The selected attribute shouldn't be empty, so
<option selected=> will cause confusion (is it empty or is there an extra equals sign?) and the space and missing quotes in <option selected= selected> will cause trouble too. The following link may help you:
[w3.org...]
<option selected="selected">Ely</option>
<option selected=>Little Downham</option>
Thanks for the responses!
In my example the item selected is 'Little Downham'
So should my generated code show:
<option selected=Little Downham>Little Downham</option>
?
If anyone has any PHP knowlede to create the correct code then that would be great.
Oh by the way - Yes - I am using XHTML.
Thanks