Quote:
Originally Posted by Philip M
A select list option cannot have an id.
|
Quote:
Originally Posted by WolfShade
Options don't have "ID".. text, value.. I think that's it.
|
Quote:
Originally Posted by Philip M
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.