Populating two dropdown menus in one loop Javascript -
i'm trying populate 2 dropdown menus in javascript numbers within same loop, 1 ever populated (the last one)
for (var i=1; i<10; i++) { var option = document.createelement("option"); option.text = i; option.value = i; document.getelementbyid('first').options.add(option); document.getelementbyid('second').options.add(option); }
the element 'second' populated, other not, if put 'second' above 'first' 'first' populated.
how can without using 2 loops? have tried passing id via function loop , still same output.
thanks.
little modification in script
for (var i=1; i<10; i++) { var option = document.createelement("option"); option.text = i; option.value = i; var newoption = option.clonenode(true); document.getelementbyid('first').options.add(option); document.getelementbyid('second').options.add(newoption); }
Comments
Post a Comment