I have two problems in this page.
Problem 1
I have text box and a table, when value of the text box match with the value in the product id column in the table, the value in the quantity should be increase by 1.
When i run the debugger, i am getting the values but the if statement is not working.
Problem 2
The value of the quantity should multiply with value of price and display the result in total column. Multiplication is working for 1st row but for the 2nd row and later row its not working. For this I tried with both ID's and CLASS
NOTE
All the row are dynamically generated from backend.
Thanks in Advance..
/*Increase quanity in billing table*/
$(document).ready(function(){
$("#add").click(function () {
var product1 = parseInt(document.getElementById('billing-product-id').value);
var product2 = parseInt(document.getElementById('billing-product-id1').value);
var quanity = parseInt(document.getElementById('billing-quanity').value);
if(product1 === product2 ){
quanity = quanity + 1;
}
});
});
/*billing table total*/
$("#billing-quanity,#billing-price").keyup(function () {
$('#billing-total').val($('#billing-quanity').val() * $('#billing-price').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Billing Table -->
<div class="container-fluid billing-section">
<table class="table table-striped" id="billing-table">
<form action="" method="post">
<legend>Billing</legend>
<thead>
<tr>
<th>Product ID</th>
<th><input type="text" name="billing-product-id" id="billing-product-id" class="form-control" required></th>
<th><input type="submit" class="btn btn-primary" value="ADD" id="add"></th>
</tr>
</thead>
</form>
<thead>
<tr>
<th>S.no</th>
<th>Product ID</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
</tbody>
</table>
</div>