Jump to content

Archived

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

nezbie

Problem with passing multiple selection list values to another one

Recommended Posts

[code]<script language="javascript">
  function doCopy(list1, list2) {
    
    for (var i=0; i< list1.length; i++) {
      
      if (list1.options[i].selected == true) {
        
        var cancopy = true;
        
        for (var j=0; j< list2.length; j++) {
          
          if (list1.options[i].value == list2.options[j].value) {
            
            cancopy = false; break;
        
          }
          
        }
        
        if (cancopy == true) {
          
          list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true); }
      
      }
      
    }
    
  }
</script>

<form name="notifications_form">

<select multiple size=5 name="jakelulista" style="width: 150px;">
  <option value="1">1
  <option value="2">2
  <option value="3">3
</select>

<input type="button" value="Siirrä arvo" onClick="doCopy(document.notifications_form.jakelulista,document.notifications_form.lopullinen);" />

<select multiple size=5 name="lopullinen" class="inputFields" style="width: 150px;"></select>

</form>[/code]

Ok, the code is above. It works fine. But, I'd need to pass multiple values in this selection list via the form. Now, when the name is just "lopullinen" it passes the last value in this list. I've tried different things to change this lists name in an array type name, like "lopullinen[]" when it can pass multiple values via the form, but the script stops working.

Can someone help me with this, please?

Share this post


Link to post
Share on other sites
document.notifications_form.elements['lopullinen[]'] solved the problem.

Share this post


Link to post
Share on other sites

×

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.