Select a checkbox field, if one or two options are chosen in the select field

-1

I have a selection field with 4 options. If option 1 is chosen, I want it to check a checkbox field (WHITE)

How do I

    
asked by anonymous 17.10.2018 / 21:19

1 answer

1

Try with a JS like this

$('select[name="opcoes"]').on('change', function(){
  $('.checks').find('input[type="checkbox"]').each(function(){
    $(this).prop('checked', false);
  });
  if($(this).val() !== ''){
    $('input[data-id="'+$(this).val()+'"]').prop('checked', true);  
  }
});

I did a fiddle to demonstrate

    
17.10.2018 / 21:48