简体   繁体   English

如何从动态表中获取输入值数组

[英]How to get array of input value from dynamic table

I created a dynamic table of course list with 4 elements of input value each row.我创建了一个动态表的课程列表,每行包含 4 个输入值元素。

<table id="tblCourse">
    <tr>
        <td>TXID</td>
        <td>CourseID</td>
        <td>Description</td>
        <td>Amount</td>
    </tr>

    <tr>
        <td><input type="text" name="TxID[0]"value=""  /></td>
        <td><input type="text" name="CourseID[0]"value="C101"  /></td>            
        <td><input type="text" name="CourseDesc[0]"value="C#.NET"  /></td>
        <td><input type="text" name="Amount[0]"value="100.00"  /></td>
    </tr>
    <tr>
        <td><input type="text" name="TxID[1]"value=""  /></td>
        <td><input type="text" name="CourseID[1]" value="C102" /></td>
        <td><input type="text" name="CourseDesc[1]" value="Php" /></td>
        <td><input type="text" name="Amount[1]"value="200.00"  /></td>
    </tr>
</table>

How do I get the input values with jQuery and pass to php array(txid,courseid,coursedesc, amt)?如何使用 jQuery 获取输入值并传递给 php 数组(txid、courseid、coursedesc、amt)? TIA TIA

The way you named your input fields they are already PHP Arrays once sent to a php script, but it would be four arrays您命名输入字段的方式一旦发送到 php 脚本,它们已经是 PHP Arrays,但它将是四个 ZA3954F9D0CE2F7CZ

$_POST['TxID'][] (1 and 2)
$_POST['CourseID'][] (1 and 2)
...

You have to name your fields a little different.你必须为你的字段命名有点不同。

<tr>
    <td><input type="text" name="coursedata[1][TxID]" /></td>
    <td><input type="text" name="coursedata[1][CourseID]" />C101</td>            
    <td><input type="text" name="coursedata[1][CourseDesc]" />C#.NET</td>
    <td><input type="text" name="coursedata[1][Amount]" />100.00</td>
</tr>

Of course you still need to count up for each new entry (1, 2, 3..).当然,您仍然需要为每个新条目(1、2、3..)进行计数。 That way you would get one array "$_POST['coursedata']" and $_POST['coursedata'][1] with the value of the input field.这样,您将获得一个数组 "$_POST['coursedata']" 和 $_POST['coursedata'][1] 与输入字段的值。 I think that should work.我认为这应该有效。 Also, you should start counting with 0.此外,您应该从 0 开始计数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM