Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.