Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery find() checkbox with a certain value

Tags:

jquery

find

I have a list of checkboxes like so below wrapped in a div.

<div>
<input type="checkbox" value="1" class="checkbox"/><br>
<input type="checkbox" value="2" class="checkbox"/><br>
<input type="checkbox" value="3" class="checkbox"/>
</div>
<select class="value">
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>

Using jquery, i would like on change for the select option, the checkbox with the value 1 to be checked.

like image 527
Lightwaxx Avatar asked Feb 16 '26 02:02

Lightwaxx


2 Answers

Try:

$(".value").change(function() {
    $('input[type=checkbox][value=1]').prop('checked', true);
});
like image 155
tymeJV Avatar answered Feb 19 '26 04:02

tymeJV


// Call the select list on change event 
$(".value").change(function() {

    // Reset all the check-boxes ckecked
    $('input:checkbox').prop('checked', false);

    // Set the chekbox with the same value as select option
    $('input:checkbox[value="' + $(this).val() + '"]').prop('checked', true);
});

DEMO HERE

like image 27
palaѕн Avatar answered Feb 19 '26 03:02

palaѕн



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!