Update Stock Input Value for each Same Item Selected
I have a problem, I need to update the stock value (real-time) for each select box that has the same Item, for example on the image attached, there are two select input that has the same item.
I want the stock quantity on the second row to be updated depending on the difference of stock quantity and quantity input.
Example:
1st Row: QTY: 3000 , STOCK : 6000
2nd Row: QTY: 5000 , STOCK : 3000 (3000 because on the 1st row the stock has been deducted by 3000)
Hope you can help. Here's my code below, Thank you
- $('select[name="selector[]"]').change(function () {
- $.ajax({
- url: 'changeitem',
- context: this,
- dataType: 'json',
- data: {
- 'itemid': this.value
- },
- success: function(info) {
- var soid = $('#soid').val();
- $(this).closest('td').next().next().find("#xstock").val(info.stock);
- $.ajax({
- url: 'getsoitemqty',
- context: this,
- dataType: 'json',
- data: {
- 'itemid': this.value,
- 'soid': soid
- },
- success: function(info) {
- $(this).closest('td').next().find("#xqty").val(info.qty);
- var stock = 0;
- var qty = 0;
- var needed = 0;
- stock = $(this).closest('td').next().next().find("#xstock").val();
- qty = $(this).closest('td').next().find("#xqty").val();
- needed = parseInt(qty) - parseInt(stock);
- if(needed<=0) {
- needed = 0;
- }
- $(this).closest('td').next().next().next().find("#xneedqty").val(needed);
- }
- });
- }
- });
- });