I was wondering how will I be able to get the values from the array generated by the code and then be able to add them in a single variable:
var selector = 'input[name^="Textbook"]';
$(selector).on('click', function() {
var checked = $(selector + ':checked').map(function() {
return {
'type': this.type,
'value': this.value
};
}).get().filter(function(o) {
return '-1' !== o.value; // skip if value = -1(No)
});
console.log('checked inputs', checked);
});
}
I have checked functions in javascript such as .reduce which according to developer.mozila.org "reduces it to a single value". Though my goal is to add only the numeric values and the array has non-numeric values as well. How can i accomplish this? Thanks!
EDIT: Here's an example of an array that the code above through the variable "checked" could output:
My goal is to add all the 'value' data and ignore the non-numeric ones.
EDIT2: Here's the HTML code. Not too sure how i could show you a working version as it relies on PHP as well and sites such as jsfiddle doesn't support it.
<label class="radio-inline">
<input form="ES4S" type="radio" name="Supplies1" value="'.$Result[$i]['ID'].'"> Yes
<input form="ES4S" type="hidden" style="display:none" value="'.$Result[$i]['ID'].'" name="SuppliesID'.$i.'">
</label>
<label class="radio-inline">
<input form="ES4S" type="radio" name="Supplies1" value="-1">No
</label>