Monkuar Posted September 10, 2012 Share Posted September 10, 2012 <select id="edit" name=edittime[]> <option value=1>1</option> <option value=2>2</option> <option value=3>3</option> <option value=4>4</option> </select> Okay, heres the catch, I have 5 of these on my page. I am using this javascript to change the value of ALL OF THEM. But it only changes the value of the first SELECT? I need it to change the value for all SELECTS with the id=edit. <script type="text/javascript"> function editall(options){ for(index = 0; index < 25; index++){ document.getElementById('edit').value=options; } } </script> editall is called from: <select name="change" style='width:40px' id="change" onchange=editall(this.value)> <option value="3">3</option> <option value="6">6</option> <option value="12">12</option> <option value="15">15</option> <option value="30">30</option> <option value="60">60</option> <option value="90">90</option> </select> Any idea guys? It should change the value for ALL selects with the id = 'edit'... but it only changes the first select ? So weird. Link to comment https://forums.phpfreaks.com/topic/268197-need-to-change-all-values/ Share on other sites More sharing options...
xyph Posted September 10, 2012 Share Posted September 10, 2012 You should only have 1 select with an ID of 'edit' IDs are unique. Link to comment https://forums.phpfreaks.com/topic/268197-need-to-change-all-values/#findComment-1376571 Share on other sites More sharing options...
Monkuar Posted September 10, 2012 Author Share Posted September 10, 2012 You should only have 1 select with an ID of 'edit' IDs are unique. thanks, i used getelementsbyName instead function editall(options){ var boxes = document.getElementsByName('edittime[]'); for (var i = 0, j = boxes.length; i < j; i++) { var an_element = boxes[i]; an_element.value=options; } } so far it works, lol topic solved Link to comment https://forums.phpfreaks.com/topic/268197-need-to-change-all-values/#findComment-1376575 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.