I am currently developing an Invoicing System where the Rate(Amount) value changes automatically when the Product(Item) is changed.
The issue I am encountering is that when I change the first Product, all the other Product Rates change to the Rate of the first Item.
Below is the jQuery code snippet to change the Rate when a Product is selected:
//Values and Inputs
$(document).on('change', '.Item', function() {
var Item = $('.Item').closest('.Item').val();
$.ajax({
type: 'GET',
url: 'AjaxPrice.php',
data: { Item: Item },
success: function(response) {
$('.Rate').val(response);
}
});
});
Here is the code snippet for the Predefined Table:
<tbody class="TableBody">
<tr>
<td style="width: 220px">
<input type="text" class="form-control Item" name="Item" id="Item" placeholder="Product Name" required autocomplete="off">
</td>
<td>
<input type="number" name="QTV" min="1" name="QTV" id="QTV" class="form-control text-right" placeholder="00" required>
</td>
<td>
<input step="2" type="number" class="form-control text-right Rate" min="1" id="Rate" placeholder="0.00" readonly>
</td>
<td>
<input step="any" id="Disc" name="Disc" type="number" min="0" name="" class="form-control text-right" placeholder="00">
</td>
<td>
<input type="text" name="SubTotal" class="form-control text-right" id="Total" placeholder="Total" readonly>
</td>
<td>
<button type="button" class="btn btn-danger DelRow">Delete</button>
</td>
</tr>
</tbody>
Below is the code snippet to Add a new Item:
$('#AddNewItem').click(function() { $('.TableBody').append(`
<tr>
<td style="width: 220px">
<input type="text" class="form-control Item" name="Item" id="Item" placeholder="Product Name" required autocomplete="off">
</td>
<td>
<input type="number" name="QTV" min="1" name="QTV" id="QTV" class="form-control text-right" placeholder="00" required>
</td>
<td>
<input step="2" type="number" class="form-control text-right Rate" min="1" id="Rate" placeholder="0.00" readonly>
</td>
<td>
<input step="any" id="Disc" name="Disc" type="number" min="0" name="" class="form-control text-right" placeholder="00">
</td>
<td>
<input type="text" name="SubTotal" class="form-control text-right" id="Total" placeholder="Total" readonly>
</td>
<td>
<button type="button" class="btn btn-danger DelRow">Delete</button>
</td>
</tr>
`); });
Any assistance with this issue would be greatly appreciated.