当我按下"添加类别"按钮它将创建一个记录,它显示我使用ajax添加类别按钮的字段。这很好。
在这里,当我按下更新按钮时,我有另一个名为Update的按钮我需要更新通过按Add Category按钮动态创建的所有字段。
<div id="tabs">
<ul>
<li><a href="#tabs-1">Request Options</a></li>
<li><a href="#tabs-2">User Options</a></li>
</ul>
<div id="tabs-1" >
<form method="GET">
<h3>Request Options</h3>
<p>Request Categories refer to the problem type of the Request. Sorting is based on rank first, and then is alphabetic.</p>
<table align="center">
<tr>
<td><b>Add Category</b></td>
</tr>
<tr>
<td>Category Name:</td>
<td><input type="text" name="cname" id="cname"/></td>
</tr>
<tr>
<td>Rank</td>
<td><input type="number" name="ranknum" id="ranknum"/></td>
</tr>
<tr>
<td><input type="button" name="addcategory" align="right" value="Add Category" onclick="ajaxFunction()"/></td>
</tr>
</table>
<div id='ajaxDiv'>
<?php
include 'config.php';
$query = "SELECT * FROM rcategories ";
//Execute query
$qry_result = mysql_query($query) or die(mysql_error());
$i=0;
//Build Result String
$display_string = "<table width='100%'>";
$display_string .= "<tr>";
$display_string .= "<th>sno</th>";
$display_string .= "<th>category</th>";
$display_string .= "<th>rank</th>";
$display_string .= "</tr>";
// Insert a new row in the table for each person returned
while($row = mysql_fetch_array($qry_result)){
$i++;
$display_string .= "<tr>";
$display_string .= "<td>$i</td>";
$display_string .= "<td><input type='text' id='inp1' name='inp1' value='$row[cname]' /></td>";
$display_string .= "<td><input type='number' id='inp2' name='inp2' value='$row[rank]'/></td>";
$display_string .= "<td><a href='#' onclick='deleteFunction($row[id])'>Delete?</a></td>";
$display_string .= "</tr>";
}
$display_string .= "</table>";
echo $display_string;
?>
</div>
<input type=submit name=update value=update />
</form>
</div>
答案 0 :(得分:1)
当动态字段显示为字段生成id并使用j-query或javascript获取此id的值并使用ajax发布值并更新您想要的字段