I am trying to follow this quesiton
How to retrieve value from elements in array using jQuery
like in my form. each table row has multiple inputs that are in the name attribute and it is an array.
<td><input type="number" name="quantity[]" class="form-control"></td>
<td><input type="number" name="unit[]" class="form-control"></td>
<td><input type="text" name="item_description[]" class="form-control"></td>
<td><input type="number" name="stock_no[]" class="form-control"></td>
<td><input type="number" name="eunitcost[]" class="form-control"></td>
and in my javascript code is this.
var counter = $("input[name^= 'quantity']").length;
var array1 = $("input[name^= 'quantity']");
var array2 = $("input[name^= 'unit']");
var array3 = $("input[name^= 'item_description']");
var array4 = $("input[name^= 'stock_no']");
var array5 = $("input[name^= 'eunitcost']");
var array6 = $("input[name^= 'ecost']");
var i;
for(i=0;i<counter;i++){
$.ajax({
url: 'http://localhost/pm/admin/service/user-service.php',
type: 'POST',
dataType: 'json',
data: {
operation: 'pr-items',
pr_no: $('#prno').val(),
quantity: array1.eq(i).val(),
unit: array2.eq(i).val(),
item_description: array3.eq(i).val(),
stock_no: array4.eq(i).val(),
eunitcost: array5.eq(i).val(),
ecost: array6.eq(i).val
},
success: function(data) {
alert('pr items success');
//todo
},
error: function(data){
alert('pr items error');
//todo
}
});
}
what seems to be the problem why my arrays can't enter in ajax data?