I want to dynmically add some options to drop down box.but i want to mark one of them as selected .How can i do it?
DropdownBox = document.getElementById("xyzid");
var optn = document.createElement("OPTION");
optn.text="txt";
optn.value="value";
DropdownBox.options.add("values");
the above code is executed inside l开发者_JS百科oop with diff values .How can i mark one as selected?
DropdownBox.options[0].selected = true;
Change the index as needed.
Update:
HTML/JavaScript - Choose dropdown options using JavaScript
精彩评论