title: Dynamic drop down list not working
body: <p>I am trying to pass a js var to a php var, then use that php var to go through and array and populate a drop down list. I can see that the php var is getting the right value but list2 and list3 are not being populated.</p>
  
  <p>If I put the string in myself <code>$list1 = 'somestring';</code> it works, but when I use <code>$list1 = $_POST['choice'];</code> it doesn't work.</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){ 
      $("#list1").change(function(){
          var selected = this.value;
      $.post("my.php", { choice: selected }, function(data){ 
            alert(data); 
      });
    });
  });
  &lt;/script&gt;
  
  &lt;?php
  echo'
  &lt;form name="menu"&gt;
   &lt;div&gt;
    &lt;select name="list1" size="1" onchange="setOptions(document.menu.list1.options
    [document.menu.list1.selectedIndex].value,document.menu.list2,document.menu.list3);"&gt;
      &lt;option value=" " selected&gt;&lt;/option&gt;
      &lt;option value="one"&gt;item1&lt;/option&gt;
      &lt;option value="two"&gt;item2&lt;/option&gt;
      &lt;option value="three"&gt;item3&lt;/option&gt;
      &lt;option value="four"&gt;item4&lt;/option&gt;
    &lt;/select&gt;&lt;br&gt;&lt;br&gt;
    &lt;select name="list2" size="1"onchange="setOptions(document.menu.list2.options
    [document.menu.list2.selectedIndex].value,document.menu.list3,' ');"&gt;
      &lt;option value=" " selected&gt;Select an option&lt;/option&gt;
    &lt;/select&gt;&lt;br&gt;&lt;br&gt;
    &lt;select name="list3" size="1"&gt;
      &lt;option value=" " selected&gt;Select an option&lt;/option&gt;
    &lt;/select&gt;&lt;br&gt;
   &lt;/div&gt;
  &lt;/form&gt;';
  ?&gt;
  </code></pre>
  
  <p>Drop down list</p>
  
  <pre><code>&lt;script&gt;
    function setOptions(chosen, selbox, selbox2) 
    {
    selbox.options.length = 0;
  
    if (chosen == " ")
    {
      selbox.options[selbox.options.length] = new Option('Select an option',' ');
      selbox2.options[selbox2.options.length] = new Option("Select an option"," ");
      setTimeout(setOptions(' ',document.menu.list3),5);
    }
  
       if (chosen == "one")
       {
         showList2(selbox);
       }
       if (chosen == "two")
       {
         showList2(selbox);
       }
       if (chosen == "three")
       {
         showList2(selbox);
       }
       if (chosen == "four")
       {
         showList2(selbox);
       }
  
       //some code snipped
     }
  
  
    function showList2(selbox)
    {
    &lt;?php
    $n = 0;
    $list1 = $_POST['choice'];
  
      foreach($list[$list1] as $key =&gt; $value)
      {
        $key_array[$n] =  $key;
        $Lname[$n] = $list[$list1][$key]['name'];
  
      $n++;
      }
  
    $jsArray = json_encode($key_array);
    echo "var jsKeys = ". $jsArray . ";";
    $jsArray = json_encode($Lname);
    echo "var jsNames = ". $jsArray . ";";
    ?&gt;
  
      for (var i=0;i&lt;jsKeys.length;i++)
      {
      var result = selbox2.options[selbox2.options.length] = new Option(jsNames[i],jsKeys[i]);
  
        if(i == jsKeys.length-1)
        {
          var result = setTimeout(setOptions(jsKeys[0],document.menu.list3,' '),5);
        }
      }
    return(result);
    }
  &lt;/script&gt;
  </code></pre>