Select option change using DOM

As far as my understanding of HTML DOM aka DHTML goes, is that if the
DOM structure of HTML document is changed programmatically using
JavaScript in the browser, it immediately gets reflected in the page’s
view. For example, if following code is executed on say a click of a

var f = document.getElementById(“f1″); // f1 is id of a form
var i = document.createElement(“input”);
i.setAttribute(“type”, “text”);

the page immediately shows the new textbox under that form. But in the
following code, this doesnt happen.

the option in combo box remains same. I checked in Firebug that the
attribute is added properly. Using the selected attribute works. Why

Thanks in advance,


c.selectedIndex = 1;
Pasted from W3C’s DOM2-HTML Specification:

Interface HTMLOptionElement

selected of type boolean
Represents the current state of the corresponding form control, in an
interactive user agent. Changing this attribute changes the state of
the form control, but does not change the value of the HTML selected
attribute of the element.




电子邮件地址不会被公开。 必填项已用*标注