开发者

adding options to drop down box dynamically

开发者 https://www.devze.com 2023-02-08 05:17 出处:网络
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?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号