I have written some code below to append the form inputs both with hidden and visible. But when I click on my add icon nothing happens. Below is the Code I have written. The Append button with id="add" isn't working. Can someone please help me with the right thing do.
<script type="text/javascript">
$(document).ready(function() => {
var num = 1;
$("#add").click(function() => {
var c = "<tr id=\"row" + num + "\"> <td><select class=\"form-control form-select select2\" data-bs-placeholder=\"Select\" name=\"model[]\" required=\"\" id=\"model\"><?php $readALL1 = "SELECT * FROM productmodels WHERE deleted = 0"; $displayAll1 = mysqli_query($conn,$readALL1); while($rowFetchAll1 = mysqli_fetch_array($displayAll1)){ $modelName = $rowFetchAll1['modelName']; $modelid = $rowFetchAll1['modelID']; ?> <option value="<?=$modelid?>"><?=$modelName?></option><?php } ?></select></td> <td> <input type=\"text\" name=\"serialN0[]\" class=\"form-control\" placeholder=\"Serial No...\"> <input type=\"text\" name=\"addedBy[]\" class=\"form-control\" id=\"addedBy\" value="<?=$_SESSION['user_uniq_id']?>" hidden=""> <input type=\"text\" name=\"deviceID[]\" class=\"form-control\" value="<?=time()?>" id=\"deviceID\" hidden=""></td><td><a href=\"javascript:;\" type=\"button\" id=\"add\" class=\"text-danger\" onclick=\"DeleteRow(" + num + ");\"><i class=\"fe fe-minus-circle\" style=\"font-size:1.6em;\"></i></a></td> </tr>";
$("tbody").append(c);
num++;
});
});
function DeleteRow(id) {
$('#row' + id).remove();
}
</script>
<div class="card-body">
<form id="" method="POST" autocomplete="off" novalidate="novalidate">
<table class="table border text-nowrap text-md-nowrap table-striped mb-0">
<thead>
<tr>
<th>Device Model</th>
<th>Serial No</th>
<th>Action</th>
</tr>
</thead>
<tbody class="field_wrapper">
<tr id="row0">
<td>
<select class="form-control form-select select2" data-bs-placeholder="Select" name="model[]" required="" id="model">
<?php
$readALL1 = "SELECT * FROM productmodels WHERE deleted = 0";
$displayAll1 = mysqli_query($conn,$readALL1);
while($rowFetchAll1 = mysqli_fetch_array($displayAll1)){
$modelName = $rowFetchAll1['modelName'];
$modelid = $rowFetchAll1['modelID'];
?>
<option value="<?=$modelid?>"><?=$modelName?></option>
<?php } ?>
</select>
</td>
<td>
<input type="" name="" class="form-control" placeholder="Serial No...">
<input type="text" name="addedBy[]" class="form-control" id="addedBy" value="<?=$_SESSION['user_uniq_id']?>" hidden="">
<input type="text" name="client[]" class="form-control" value="<?=$clientID?>" id="client" hidden="">
<input type="text" name="deviceID[]" class="form-control" value="<?=time()?>" id="deviceID" hidden="">
</td>
<td><button type="button" id="add" class=" btn text-success"><i class="fe fe-plus-circle" id="add" style="font-size:1.6em;"></i></button></td>
</tr>
</tbody>
</table>
</form>
</div>