title: Javascript fill select box
body: <p><strong>[Code]</strong></p>
  
  <pre><code>$.ajax
  ({
      'method': 'GET',
      'source': '/bpv-registratie/periods/show_period_list_by_year.html',
      'charge': function () 
      {
      },
      'finish': function (xmlHttp) 
      {       
          var options = new Array();
          var response = eval('(' + xmlHttp.responseText + ')');                                              
  
          var child = document.createElement('option');
          child.setAttribute('value', 'none');
          child.setAttribute('checked', 'checked');
          child.innerHTML = '&amp;nbsp';
  
          options.push(child);
  
          for (var c = 0; c &lt; response.length; c++)
          {
              var child = document.createElement('option');
              child.setAttribute('value', response.data[c].periode_id);
              child.innerHTML = response.data[c].periode_naam +
                                ' (' + 
                                response.data[c].periode_startdatum +
                                ' t/m ' +
                                response.data[c].periode_einddatum +
                                ' )';             
              options.push(child);
          }                                               
          for (var a = 0; a &lt; obj.childNodes.length; a++)
          {
              var e = obj.childNodes[a].getElementsByTagName("select");
  
              for (var f = 0; f &lt; e.length; f++)
              {       
                  e[f].length=0;                  
                  for (var o = 0; o &lt; options.length; o++)
                  {               
                      e[f].appendChild(options[o]);               
                  }
              }
          alert('test');
          }   
      }
  });
  </code></pre>
  
  <p><strong>[Problem]</strong></p>
  
  <p>Running the code above with the alert, it shows that all the select boxes do get filled with the options I want them to. However as soon as it starts filling the next select box, the previous is being cleared again.
  Does anyone know why?</p>
  
  <p><strong>[Situation]</strong></p>
  
  <p>I have a bunch of select boxes generated from about the same code. These represent a class a person can be in. The class should be selected from the selectbox. However if the teacher wishes to change the person to a different period, that would most likely mean that there are different classes available in that period so what I'm trying to do is fill the select boxes with the classes from the new period.</p>