OK so I have a bunch of inputs like so:
<input type="number" name="quantity" value="0" data-id="100">
<input type="number" name="quantity" value="1" data-id="101">
<input type="number" name="quantity" value="2" data-id="102">
<input type="number" name="quantity" value="3" data-id="103">
<input type="number" name="quantity" value="0" data-id="104">
<button data-ids=""></button>
I want to loop through these and get the data-id and value from inputs that have a value more than 0 and output it to the buttons data-ids attribute like so:
<button data-ids="101:1,102:2,103:3"></button>
Here is the code i have so far:
$('input').each( function(){
var input = $(this);
// Check quantity is more than 0
if ($(input).val() > '0'){
var output = input.attr('data-id') + ':' + input.val();
console.log(output);
$('button').attr('data-ids', output);
}
});
This seems to output the data in the console but only outputs the last input in the button.