当行内容来自数据库时,在按钮单击上动态添加表行

时间:2022-11-03 09:49:21

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

嗨,我正在处理一个表单,当用户点击添加按钮时,它将动态生成一个表行,但问题是我正在加载要从外部php文件生成的行,但它似乎无法工作我正在使用外部文件,因为行将包含一个组合框,将由mysql数据填充,任何人都可以帮助我在这里这是我的脚本

$(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);                        
        });
    }); 
});

here is my php

这是我的PHP

<?php
session_start();

require("includes/dbconnect.php");
include ('includes/function.php');

mysql_select_db($_SESSION["zdbname"]);

if (isset($_POST['ctr'])) {
    $ctr = $_POST['ctr'];

    echo '<tr>';

    echo '<td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="ord_'.$ctr.'" class="form-input-oth"/></td>';
    echo "<td>";
    echo '<select data-placeholder="Party" style="width:120px;" name="item_'.$ctr.'" class="chzn-select-deselect" >';
    echo "<option value = '' ></option>";
    $get = mysql_query("SELECT * FROM accmast WHERE `grpcode`='010'") or die(mysql_error());
      while($cc = mysql_fetch_array($get)){
            echo "<option value=$cc[accode]>$cc[name]</option>";
      }
    echo "</select></td>";
    echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="descrip_'.$ctr.'" class="form-input-name"/></td>';
    echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="unit_'.$ctr.'" class="form-input-rate"/></td>';
    echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="totqty_'.$ctr.'0" class="qty form-input-rate"/></td>';
    echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_'.$ctr.'" class="rate form-input-rate"/></td>';
    echo '<td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_'.$ctr.'" class="cal  form-input-amt"/></td>';
    echo "</tr>";
}
else{
    echo "ERROR";
}

here is my table

这是我的桌子

<table border="1px" width="90%" id="data">
    <tr>
        <td><br /></td>
    </tr>
    <tr>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">item</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Total Quantity</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
        <td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Amount</font><span></span></label></td>
    </tr>
    <tr>
        <td align="center"><input type="text" size="6" maxlength="6" maxlength="6" name="ord_0" class="form-input-oth"/></td>
        <td align="center">
            <select data-placeholder="Party" style="width:120px;" name="order" class="chzn-select-deselect" >
                <option>rehan</option>
            </select>
        </td>
        <td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="descrip_0" class="form-input-name"/></td>
        <td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="unit_0" class="form-input-rate"/></td>
        <td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="totqty_0" class="qty form-input-rate"/></td>
        <td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="rate_0" class="rate form-input-rate"/></td>
        <td align="center"><input type="text" size="6" maxlength="9" maxlength="6" name="amt_0" class="cal  form-input-amt"/></td>
    </tr>
    <input type="button" id="addnew" class="classname" name="addnew" value="+" /> 
    <input type="hidden" id="items" name="items" value="1" />

1 个解决方案

#1


0  

Are you sure about that? $(data).appendTo('#data') ??

你确定吗? $(data).appendTo('#data')??

Try that $('#data').appendTo(data);

试试$('#data')。appendTo(data);

#1


0  

Are you sure about that? $(data).appendTo('#data') ??

你确定吗? $(data).appendTo('#data')??

Try that $('#data').appendTo(data);

试试$('#data')。appendTo(data);