E
E
Eugene Chefranov2018-01-27 00:28:23
JavaScript
Eugene Chefranov, 2018-01-27 00:28:23

How to mark checkbox on select select?

Tell me, there is such a select

<select class="item-list" name="item-list">
<option value="item-1">Item name 1</option>
<option value="item-2">Item name 2</option>
<option value="item-3">Item name 3</option>
<option value="item-4">Item name 4</option>
</select>

And checkboxes
<div class="additionals">
<span class="checkbox-input">
<input name="add[0]" type="checkbox" value="Delivery" data-price="40" id="add-0">
<label for="add-0">Delivery - $40</label>
</span>
<span class="checkbox-input">
<input name="add[1]" type="checkbox" value="Child Seat" data-price="20" id="add-1">
<label for="add-1">Child Seat - $20</label>
</span>
<span class="checkbox-input">
<input name="add[2]" type="checkbox" value="GPS" data-price="20" id="add-2">
<label for="add-2">GPS - $20</label>
</span>			
</div>


How to make it so that if an element is selected in select - <option value="item-2">Item name 2</option>, then a checkmark with
<input name="add[0]" type="checkbox" value="Delivery" data-price="40" id="add-0">
should be removed, and in other cases stood.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-01-27
@Chefranov

$('select').on('change', function(){
  $('#add-0').prop('checked', this.value === 'item-2')
})
https://jsfiddle.net/2hkj1dnL/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question