View Single Post
Old 03-13-2013, 06:53 AM   PM User | #16
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,887
Thanks: 5
Thanked 186 Times in 183 Posts
Arbitrator is on a distinguished road
Quote:
Originally Posted by Philip M View Post
A select list option cannot have an id.
Quote:
Originally Posted by WolfShade View Post
Options don't have "ID".. text, value.. I think that's it.
Quote:
Originally Posted by Philip M View Post
Yes, I think that has been made clear already. Text, value and selectedIndex.
This isn't true; option elements can have id attributes. See:
As far as I can tell, there's no longer a restriction on characters allowed in IDs other than spaces in HTML5, so that would make this solution viable:

Code:
<!doctype html>
<html lang="en-US">
	<head>
		<title>Demo Document</title>
	</head>
	<body>
		<select>
			<option value="">-First Select Color-</option>
			<option id="1993" value="1993">N:Navy</option>
			<option id="1997" value="1997">BK:Black</option>
			<option id="2200" value="2200">O:Orchid</option>
		</select>
		<script>
			function select_option(option_value) {
				document.getElementById(option_value).selected = true;
			}
			select_option("1993");
		</script>
	</body>
</html>
Logic Ali's solution is a more straightforward (and still standards-compliant) though.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *

Last edited by Arbitrator; 03-13-2013 at 07:02 AM.. Reason: I fixed several typos.
Arbitrator is offline   Reply With Quote