javascript - dynamic variable.optiones.selected -
i'm new here in forum first question. if wrong it. question: i've got multiple select in html file values save in database. when site loaded again select select options selected before automaticly. need this:
<select multiple id="a"> <option>tomato</option> </select> <select multiple id="b"> <option>apple</option> </select> <select multiple id="c"> <option>orange</option> </select> <select multiple id="d"> <option>cake</option> </select> <script> var ids = ["a", "b", "c", "d"]; for(i=0, < 4, i++){ var id = ids[i]; id.options[0].selected = true; } </script>
this tried (on web page selects have more 1 option). i've done research in internet, not able find results. problem dynamic variable it's interpreted it's id of html object compiler should interpreted variable. need right syntax. couldn't work because there error whit dyanamic variable. how can right, works?
so done lot o research again , done way:
document.getelementbyid(id).options[0].selected = true;
Comments
Post a Comment