title: Dynamically add a table row on a button click when row content comes from database
body: <p>hi i am working on a form which will dynamically generate a table row when a user clicks on the the add button but the problem is i am loading the row to be generated from an external php file but it not seems to work i am using an external file because the row will contain a combo box will which will be populated by mysql data can anyone help me in this
  here is my script</p>
  
  <pre><code>$(document).ready(function() {
      //var currentItem = $('#items').val();
      $('#addnew').click(function(){
          var ctr = $('#items').val();
          ctr++;
          $.post('purch_srch.php', {ctr : ctr}, function(data) {
              $(data).appendTo('#data')
              $('#items').val(ctr);                        
          });
      }); 
  });
  </code></pre>
  
  <p>here is my php</p>
  
  <pre><code>&lt;?php
  session_start();
  
  require("includes/dbconnect.php");
  include ('includes/function.php');
  
  mysql_select_db($_SESSION["zdbname"]);
  
  if (isset($_POST['ctr'])) {
      $ctr = $_POST['ctr'];
  
      echo '&lt;tr&gt;';
  
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="6" maxlength="6" name="ord_'.$ctr.'" class="form-input-oth"/&gt;&lt;/td&gt;';
      echo "&lt;td&gt;";
      echo '&lt;select data-placeholder="Party" style="width:120px;" name="item_'.$ctr.'" class="chzn-select-deselect" &gt;';
      echo "&lt;option value = '' &gt;&lt;/option&gt;";
      $get = mysql_query("SELECT * FROM accmast WHERE `grpcode`='010'") or die(mysql_error());
        while($cc = mysql_fetch_array($get)){
              echo "&lt;option value=$cc[accode]&gt;$cc[name]&lt;/option&gt;";
        }
      echo "&lt;/select&gt;&lt;/td&gt;";
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="descrip_'.$ctr.'" class="form-input-name"/&gt;&lt;/td&gt;';
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="unit_'.$ctr.'" class="form-input-rate"/&gt;&lt;/td&gt;';
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="totqty_'.$ctr.'0" class="qty form-input-rate"/&gt;&lt;/td&gt;';
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="rate_'.$ctr.'" class="rate form-input-rate"/&gt;&lt;/td&gt;';
      echo '&lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="amt_'.$ctr.'" class="cal  form-input-amt"/&gt;&lt;/td&gt;';
      echo "&lt;/tr&gt;";
  }
  else{
      echo "ERROR";
  }
  </code></pre>
  
  <p>here is my table</p>
  
  <pre><code>&lt;table border="1px" width="90%" id="data"&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;br /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Order&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;item&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Description&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Unit&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Total Quantity&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Rate&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
          &lt;td width="130px" align="center"&gt;&lt;label for=""&gt;&lt;font color="#0099FF" size="3px"&gt;Amount&lt;/font&gt;&lt;span&gt;&lt;/span&gt;&lt;/label&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="6" maxlength="6" name="ord_0" class="form-input-oth"/&gt;&lt;/td&gt;
          &lt;td align="center"&gt;
              &lt;select data-placeholder="Party" style="width:120px;" name="order" class="chzn-select-deselect" &gt;
                  &lt;option&gt;rehan&lt;/option&gt;
              &lt;/select&gt;
          &lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="descrip_0" class="form-input-name"/&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="unit_0" class="form-input-rate"/&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="totqty_0" class="qty form-input-rate"/&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="rate_0" class="rate form-input-rate"/&gt;&lt;/td&gt;
          &lt;td align="center"&gt;&lt;input type="text" size="6" maxlength="9" maxlength="6" name="amt_0" class="cal  form-input-amt"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;input type="button" id="addnew" class="classname" name="addnew" value="+" /&gt; 
      &lt;input type="hidden" id="items" name="items" value="1" /&gt;
  </code></pre>