You can easily convert the entered input fields to an array:
var checkedInputs = $("input:checked")
Now, depending on the desired result, you can either collect the values โโseparately
var barcodes = checkedInputs.map(function() { return $(this).attr('barcode') }) var amounts = checkedInputs.map(function() { return $(this).attr('amount') }) var previouss = checkedInputs.map(function() { return $(this).attr('previous') })
or, which might be even better, since objects like twilson suggested
var results = checkedInputs.map(function() { return { barcode: $(this).attr('barcode'), amount: $(this).attr('amount'), previous: $(this).attr('previous') } })
In this case, you want this be taken from inside a function call, since it refers to an object, you are matched with a call to $('input:checked') . If you store var self = this as suggested by twilson, you will not get the actual values โโof the input field, but no values, since this calling context is most likely not an HTMLElement at all.
source share