Add default post value into dynamic created input row field in php

I have two small form. I want to enter one value (Name) into another form by adding that in 2nd form. But the problem which i am facing is that for single row, its work fine, but when i created dynamic more dynamic row, then this default value missing from that dynamic created rows.

Here is my complete php code : Form 1

          <form method="POST" action="f1.php">              
           <label>Catagory:</label> <input type="text" name="name" id="name" class="form-control">
             <label>Catagory:</label> <input type="text" name="lname" id="lname" class="form-control">  
           <label>Catagory:</label> <input type="text" name="age" id="age" class="form-control">                    
          <input type="submit" name="submit" id="submit" value="Submit">


        // getting all values from the HTML form
             $name = $_POST['name'];     
$lname = $_POST['lname'];
$age = $_POST['age'];   

           // using sql to create a data entry query
            $sql = "INSERT INTO aaa(name, lname, age)
            VALUES ('$name', '$lname', '$age')";   

            // send query to the database to add values and confirm if successful
                  $rs = mysqli_query($con, $sql);
    echo "Entries added!";

               // close connection

                       <table class="table table-bordered">
                     <thead class="table-success" style="background-color: #3fbbc0;">
                        <th width="15%"><center>Name</th>                          
                       <th width="5%"></th>  
                                 <button type="button" class="btn btn-sm btn-success" onclick="BtnAdd()">Add Item</button>                         
                                 <tbody id="TBody">
                      <tr id="TRow" class="d-none">    
<td><input type="text" class="qty form-control text-end" name="name[]" id="name" value = "<?php echo $name; ?>"></td>       
<td class="NoPrint"><button type="button" class="btn btn-success"  style="line-height: 1;" onclick="BtnDel(this)">x</button></td>

script to add remove new row dynamically

<script type="text/javascript">

function GetPrint()
    /*For Print*/

function BtnAdd()
    /*Add Button*/
    var v = $("#TRow").clone().appendTo("#TBody") ;
        source: 'backend-script.php'  
    $(v).find("th").first().html($('#TBody tr').length - 1);

function BtnDel(v)
    /*Delete Button*/




Well yes, because you tell Javascript to erase the value.

Assuming you have exactly 1 default value you’re expecting in each, you may be trying to do this:

  let ip = $(v).find("input"); //Dont find more than once.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.