On Feb 6, 10:24 pm, Sebastian Fey <sebastian....@web.dewrote:
hi,
how do you select an option using javascript?
i tried to setAttribute("selected", "disabled") to disable last
setAttribute sets the HTML selected attribute, not the DOM element's
selected property. Just don't use setAttribute, set properties
directly.
Also, the selected attribute is set to boolean true or false, not some
string value so use:
someOption.selected = false;
to "unselect" an option. If the select element's selectedIndex
property is set to -1, or all the options' selected properties are set
to false, no options will be selected.
selected and setAttribute("selected", "selected") for the newly selected.
doesnt work :)
That is equivalent to the HTML <option selected ... which probably
has no effect on the currently selected option. Use:
someOtherOption.selected = true;
the last option in the list is always selected no matter which value
"selected" has.
You can either set the selectedIndex property of the select element,
or the selected property of a particular option element. There is no
need (in a single select) to set any other option's selected property
to false.
Things are a little different in a multiple-select.
--
Rob