title: xmlhttp.responsetext.split while loops
body: <p>I have some javascript that pulls some mysql data using xmlhttp.responsetext.  I've been using it to populate form data for a drop down box and it has been working well.  However, I have a need to add a second dropdown menu in the form and it is not working right.</p>
  
  <p>What is happening is both dropdowns are populating with data from 2 different tables when each dropdown should only be getting its data from its respective table.</p>
  
  <p>Could use some help figuring this out, thanks.</p>
  
  <p>Here is the javascript code.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  var counter = 1;
       function addInput(div){
          xmlhttp=new XMLHttpRequest();
          xmlhttp.onreadystatechange = function() {
           if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){
            var newdiv = document.createElement(div);
            newdiv.innerHTML = "&lt;table&gt;&lt;tr&gt;&lt;td&gt;Line Item " + (++counter) + "&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td width='190'&gt;Item: &lt;select name='item[]'&gt;" + xmlhttp.responseText.split( "[BRK]" ) + "&lt;/select&gt;&lt;/td&gt;&lt;td width='100'&gt;Qty: &lt;input name='quantity[]' type='text' size='2' /&gt;&lt;/td&gt;&lt;td width='500'&gt;Description: &lt;input name='description[]' type='text' size='60' /&gt;&lt;/td&gt;&lt;td width='150'&gt;Amount: &lt;input name='amount[]' type='text' size='6' /&gt;&lt;/td&gt;&lt;td&gt;Tax Rate: &lt;select name='taxrate[]'&gt;" + xmlhttp.responseText.split( "BRK" ) + "&lt;/select&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;";
           }
            document.getElementById(div).appendChild(newdiv);
       }
  
  xmlhttp.open("GET", "dropdownquery.php", false);
  xmlhttp.send();
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>And here is php.</p>
  
  <pre><code>&lt;?php
  include $_SERVER['DOCUMENT_ROOT']."/connect.php";
  
  $result = mysql_query("SELECT * FROM salesitem");
  $result2 = mysql_query("SELECT * FROM salestax");
  
  while($row = mysql_fetch_array($result)) {
      echo "&lt;option value=\"".$row['name']."\"&gt;".$row['name']."&lt;/option&gt;";
  }
  echo "[BRK]";    
  
  while($row2 = mysql_fetch_array($result2)) {
      echo "&lt;option value=\"".$row2['amount']."\"&gt;".$row2['name']."&lt;/option&gt;";
  }
  echo "[BRK]";    
  
  ?&gt;
  </code></pre>