I have numerous checkboxes that are prices and what I’ve tried to do is the following
When someone selects a prices/checkbox, it will automatically check the values that are less than the selected value.
HTML
<div class="prices">
<input type="checkbox" value="59.99" />59.99
<input type="checkbox" value="69.99" />69.99
<input type="checkbox" value="79.99" />79.99
<input type="checkbox" value="89.99" />89.99
<input type="checkbox" value="99.99" />99.99
<input type="checkbox" value="124.99" />124.99
<input type="checkbox" value="149.99" />149.99
<input type="checkbox" value="199.99" />199.99
<input type="checkbox" value="200.00" />200.00
</div>
JQUERY
$('.prices input[type=checkbox]').live('click', function (){
console.log(this);
$(this).attr('checked', true);
var chosenPrice = $(this).val();
console.log(chosenPrice);
$(".prices input").filter(function(){
return $(this).attr("value") <=chosenPrice}).attr('checked', true);
});
It selects some values but it doesn’t seem to work as it should be. check out the fiddle
Modified part of your code.. You need to do only check the other checkboxes when the current checkbox is checked..
Also need to convert the string to a number using
parseFloat()orNumber()Check Fiddle