I am trying to change the name attribute of an input. It is a sales order and has many inputs that collect the qty and item id.
I want the name to index like this item[0] [qty] & item [0] [id]
I was able to get most of it working however it is changing the name for all the inputs to the last one. For example I have 44 items. It is now making the name for all the inputs to be item[43] qty.
Here is part of the code I have written. Thanks for any help you can provide.
var showProduct = function(result) {
var last = $('.display:last');
$(".display ").append("<tr> <td>" + result.id + " </td> <td> "
+ result.brand + " </td> <td>"
+ result.description + "</td> <td>"
+ result.packType + " </td> <td>"
+ result.packSize + " </td> <td>"
+ result.unitsPerPallet + " </td> <td>"
+ result.shippingWeight + " </td> <td>"
+ "<input type = \"number\" class = \"qty\" > </input>
</td> </tr>"
// + "<input type=hidden name = \"id\" value = \"" + result.id
+ "\">"
);
last.find('input').val([]);
last.find('input').attr("name", "lineItem[" + i + "][qty]");
console.log(i);
i++
};