Forum Moderators: open

Message Too Old, No Replies

W3C ERROR: an attribute value specification must be an attribute value

         

JustinDia

11:58 am on Aug 8, 2004 (gmt 0)

10+ Year Member



Hi there,

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

encyclo

12:17 pm on Aug 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<option selected= selected>
Ely
</option>

<option selected=>
Little Downham
</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...]

Lance

12:29 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



I don't see where in your script the selected= is being generated, but if you wrap the value in quotes you should be good.

<option selected="selected">Ely</option>

In this line though, the selected= needs to either be removed or have a quoted value after it.

<option selected=>Little Downham</option>

JustinDia

12:46 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



Hi there,

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

encyclo

12:51 pm on Aug 8, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It should read:

<option [b]selected="selected"[/b]>
Little Downham<
/option>

Make sure you've got the quotes and no spaces.

Have you tried something like:

print " selected=\"selected\"";

for your PHP code?

JustinDia

3:49 pm on Aug 8, 2004 (gmt 0)

10+ Year Member



Thanks there,

That did the trick :)