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
button

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

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
so?

Thanks in advance,
Manish

 

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.

HTH

暂无评论

发表评论

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

您可以使用这些HTML标签和属性: