i have small php form (with dynamic generated input rows) where i need one value from previous form. that value successfully inserted in first row. but when i dynamically generate more rows than that value is not automatically insert in that rows.
here is previous form post value
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit']))
{
$id1 = $_POST['id1'];
$company = $_POST['company'];
** $empid = $_POST['empid'];**
$empname = $_POST['empname'];
}
and this is my new form where i want that empid should automatically insert in all rows.
<table class="table table-bordered">
<thead class="table-success" style="background-color: #3fbbc0;">
<tr>
<th><center>Empid</th>
<th><center>Subject</th>
<th>
<button
type="button"
class="btn btn-sm btn-success"
onclick="BtnAdd()"
>
Add Item
</button>
</th>
</tr>
</thead>
<tbody id="TBody">
<tr id="TRow" class="d-none">
<td>
<input
type="text"
name="empid[]"
id="empid"
value="<?php echo $empid; ?>"
class="zzz1 form-control text-end"
>
</td>
<td>
<input
type="text"
name="subject[]"
id="subject"
class="state form-control text-end"
required
>
</td>
<td class="NoPrint">
<button
type="button"
class="btn btn-success"
style="line-height: 1;"
onclick="BtnDel(this)"
>
x
</button>
</td>
</tr>
</tbody>
</table>
here is java script code which generate dynamic rows for input
<script type="text/javascript">
function GetPrint()
{
/*For Print*/
window.print();
}
function BtnAdd()
{
/*Add Button*/
var v = $("#TRow").clone().appendTo("#TBody") ;
$(v).find("input").val('');
$(v).find("input").autocomplete({
source: 'backend-script.php'
});
$(v).removeClass("d-none");
$(v).find("th").first().html($('#TBody tr').length - 1);
}
function BtnDel(v)
{
/*Delete Button*/
$(v).parent().parent().remove();
GetTotal();
$("#TBody").find("tr").each(function(index) {
$(this).find("th").first().html(index);
});
}
i tried following but its duplicate all the data of first rows instead of just required field which is empid
let ip = $(v).find("input"); //Dont find more than once.
ip.val(ip.prop($empid));