Each row in my table has an edit button wherein it has a javascript function to edit the data in a row. Whenever I click the edit button, all rows got affected and all input fields were enabled. At first all input fields in all rows are disabled, but when I click any edit button all input fields are affected.
I already used a class selector in my javascript function and in my button and input fields tag.
Here is my html code:
<?php
if($result = mysqli_query($conn, $sql)) {
while($row = mysqli_fetch_assoc($result)) {
?>
<tr>
<td> <?php echo $row["productname"]; ?> </td>
<td><input type="number" name="crit" id="crit" value="<?php echo $row["quantity"]; ?>" disabled></td>
<td><button type="button" name="edit" id="edit"><i class="fa fa-edit"></i></button></td>
</tr>
<?php
}
}
?>
Here is my javascript function:
$(document).ready(function() {
var button = $('#crit');
$(button).prop('disabled', true);
$('#edit').click(function() {
if ($(button).prop('disabled')) $(button).prop('disabled', false);
else $(button).prop('disabled', true);
});
});
Once I clicked the edit button of a specific row, the input field SHOULD be enabled on that row only.