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

06-09-2004, 10: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.value = options[i];

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


06-09-2004, 11: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.