javascript - Updating Multiple Select Boxes dynamically -
i have page has 2-300 select dropdown boxes. need dynamically update each 1 have same list of options. each time try update it first one. suspect problem not looping through it.
// html
<form id="myform"> <select id="selectnumber"> <option>choose number</option> </select> </form> <form id="myform"> <select id="selectnumber"> <option>choose number</option> </select> </form> <form id="myform"> <select id="selectnumber"> <option>choose number</option> </select> </form>
// javascript
var myarray = new array("1", "2", "3", "4", "5"); // dropdown element dom var dropdown = document.getelementbyid("selectnumber"); // loop through array (var = 0; < myarray.length; ++i) { // append element end of array list dropdown[dropdown.length] = new option(myarray[i], myarray[i]); }
just mike said, can't use same id field selects.
"an id should unique within page. however, if more 1 element specified id exists, getelementbyid() method returns first element in source code."
you try setting same class selects , use getelementsbyclassname(class), returns elements class.
also, if there no other select element in page aside ones want change use getelementsbytagname('select') returns select elements.