...

View Full Version : setting selected with createElement("option")



moradri
06-09-2004, 09:51 AM
Im trying to create a dropdown menu through createElement, browser is IE.
The problem is setting one of the options as "selected".

So far I have:
options = editor.config[txt];
el = document.createElement("select");

for (var i in options) {
var op = document.createElement("option");
op.appendChild(document.createTextNode(i));
op.value = options[i];
el.appendChild(op);
}

I get my dropdown menu, but how do I set selected?
Ive tried
op.selected = true
without success.
Thanks for any help on this.

-moradri-

glenngv
06-09-2004, 10:40 AM
op.selected = true works for me.

If you execute it inside the for-loop, the last element will be selected if the combo box is not set as multiple. You have to execute it only once if you want the correct option to be selected.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum