Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting SELECT menu values

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
Hi,

I'm trying to set SELECT menu values dynamically in JS.

Normally I would use:

Code:
document.getElementById('selectmenu').options[0] = "Option One";

However if I want to set the text and the value, it fails:

Code:
document.getElementById('selectmenu').options[0].text = "Option One";
document.getElementById('selectmenu').options[0].value = "1";

Any ideas?
 
in IE6 and firefox 0.8, your first example fails and the second works properly.


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 

Absolutely - the second example should work fine in most browsers.

What error are you getting, and in what browser?

Dan


 
Yeh it works fine, it was a stupid mistake I made in a switch statement. I forgot to put quotes around a case matching a number. I'm stuck in PHP logic ;-)
 
DeepBlerg,

>> "forgot to put quotes around a case matching a number"

that doesn't sound right either - this works too:
Code:
var x = 3;

switch(x) {
	case "foo":
		alert("ooga");
		break;
	case "bar":
		alert("booga");
		break;				
	case 3:
		alert("three");
		break;
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top