javascript - jQuery does not get correctly values of all checked checkbox -
i have list of checkboxes checked follow:
<input type="checkbox" name="capacity" value="16" checked> 16 <br> <input type="checkbox" name="capacity" value="32" checked> 32 <br> <input type="checkbox" name="capacity" value="64" checked> 64 <br> <input type="checkbox" name="capacity" value="128" checked> 128 <br>
each time checkbox checked or unchecked, want update capacity
list again, therefore, use (with little bit of repeating code):
$('input[name="capacity"]').change(function() { var capacity = $('input[name="capacity"]:checked').map(function() { return this.value; }).get(); console.log(capacity); })
however, capacity still contains value of last unchecked checkbox. when unchecked 128 -> capacity = ["16","32","64","128"]
. then, unchecked 32 -> capacity =["16","32","64"]
i don't understand strange behavior or doing wrong?
Comments
Post a Comment