Jump to content

Need to CHANGE ALL VALUES!


Monkuar

Recommended Posts


<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

You should only have 1 select with an ID of 'edit'

 

IDs are unique.

 

thanks,

 

i used getelementsbyName instead :P

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.