简体   繁体   中英

when i press the update button i need to update all the fields which is created dynamically using php?

When I press the "Add Category" button it'll create one record and it displays fields I am using ajax for Add Category button. That works fine.

Here, I am having another button called Update when I press the update button I need to update all the fields which is created dynamically by pressing Add Category button.

<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>

当显示动态字段时,为该字段生成一个ID,并使用j-query或javascript获取此ID的值,然后使用ajax发布该值并更新您想要的字段

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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