Jump to content

selected="selected" not working in FF but in IE?


cooldude832

Recommended Posts

I have a list of states from php being generated and if it matches the users value it should say

 

<option value="Michigan" selected="selected" >Michigan</option> (if it was Michigan for say)

 

ie selects Michigan fine, but FF shows in the source code <option value="Michigan" selected="selected" >Michigan</option>

but doesn't selected instead defaults to the first item of Alabama???

 

this is the whole outputted selected

<html>
State: <select name="state">
<option value="Alabama"  >Alabama</option>
<option value="Alaska"  >Alaska</option>
<option value="Arizona"  >Arizona</option>
<option value="Arkansas"  >Arkansas</option>
<option value="California"  >California</option>

<option value="Colorado"  >Colorado</option>
<option value="Connecticut"  >Connecticut</option>
<option value="Delaware"  >Delaware</option>
<option value="District of Columbia"  >District of Columbia</option>
<option value="Florida"  >Florida</option>
<option value="Georgia"  >Georgia</option>
<option value="Hawaii"  >Hawaii</option>
<option value="Idaho"  >Idaho</option>
<option value="Illinois"  >Illinois</option>

<option value="Indiana"  >Indiana</option>
<option value="Iowa"  >Iowa</option>
<option value="Kansas"  >Kansas</option>
<option value="Kentucky"  >Kentucky</option>
<option value="Louisiana"  >Louisiana</option>
<option value="Maine"  >Maine</option>
<option value="Maryland"  >Maryland</option>
<option value="Massachusetts"  >Massachusetts</option>
<option value="Michigan" selected="selected" >Michigan</option>

<option value="Minnesota"  >Minnesota</option>
<option value="Mississippi"  >Mississippi</option>
<option value="Missouri"  >Missouri</option>
<option value="Montana"  >Montana</option>
<option value="Nebraska"  >Nebraska</option>
<option value="Nevada"  >Nevada</option>
<option value="New Hampshire"  >New Hampshire</option>
<option value="New Jersey"  >New Jersey</option>
<option value="New Mexico"  >New Mexico</option>

<option value="New York"  >New York</option>
<option value="North Carolina"  >North Carolina</option>
<option value="North Dakota"  >North Dakota</option>
<option value="Ohio"  >Ohio</option>
<option value="Oklahoma"  >Oklahoma</option>
<option value="Oregon"  >Oregon</option>
<option value="Pennsylvania"  >Pennsylvania</option>
<option value="Rhode Island"  >Rhode Island</option>
<option value="South Carolina"  >South Carolina</option>

<option value="South Dakota"  >South Dakota</option>
<option value="Tennessee"  >Tennessee</option>
<option value="Texas"  >Texas</option>
<option value="Utah"  >Utah</option>
<option value="Vermont"  >Vermont</option>
<option value="Virginia"  >Virginia</option>
<option value="Washington"  >Washington</option>
<option value="West Virginia"  >West Virginia</option>
<option value="Wisconsin"  >Wisconsin</option>

</select><br />
</html>

 

as you can see Michigan is selected but FF decides to highlight Alabama instead

 

Link to comment
Share on other sites

I think it must be an error outside the selected tags because I have a very similar code that functions fine.

 

 

 

State:
  <select name="state">
<option value="bama">AL</option>
<option>AK</option>
<option>AS</option>
<option>AZ</option>
<option>AR</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DE</option>
<option>DC</option>
<option>FM</option>
<option>FL</option>
<option>GA</option>
<option>GU</option>
<option>HI</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>IA</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>ME</option>
<option>MH</option>
<option value="maryland" selected="selected">MD</option>
<option>MA</option>
<option>MI</option>
<option>MN</option>
<option>MS</option>
<option>MO</option>
<option>MT</option>
<option>NE</option>
<option>NV</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NY</option>
<option>NC</option>
<option>ND</option>
<option>MP</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PW</option>
<option>PA</option>
<option>PR</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VT</option>
<option>VI</option>
<option>VA</option>
<option>WA</option>
<option>WV</option>
<option>WI</option>
<option>WY</option>
</select> 

Link to comment
Share on other sites

yeah but w3 says

<option value="Michigan"  selected  >Michigan</option>

 

"VI delimiter" is a technical term for the equal sign. This error message means that the name of an attribute and the equal sign cannot be omitted when specifying an attribute. A common cause for this error message is the use of "Attribute Minimization" in document types where it is not allowed, in XHTML for instance.

 

How to fix: For attributes such as compact, checked or selected, do not write e.g <option selected ... but rather <option selected="selected" ...

 

shouldn't be that the right way fails :(

Link to comment
Share on other sites

I've used this a million times

<?php
		echo "State: <select name=\"state\">\n";
			foreach($states as $value){
				echo "<option value=\"".$value."\" ";
				if($_SESSION['Fields']['state'] == $value){
				echo "selected ";
				}
			echo " >".$value."</option>\n";
		}
		echo "</select><br />\n";
?>

but the w3 says the whole output is valid

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.