More than one value in a variable id

1

Select:

<div class="span2" class="checks" >
   <h4>BRANCO</h4>
   <img src= "/images/cor-05.jpg"  width="57" height="27">
   <input type="checkbox" data-id="TRANSPARENTE" name="cor5" value="BRANCO"  />
   <label for="lineatura5">Lineatura<span class="required"></span></label>
   <select class="span6" name="lineatura5" id="lineatura5" value="">
      <option value="">Selecione</option>
      <option value="52">52</option>
      <option value="42">42</option>
   </select> 
</div>

Function:

$('select[name="substrato_imprime"]').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);  
  }
});

Checkbox:

<input type="checkbox" data-id="TRANSPARENTE" name="cor5" value="BRANCO" />

In a select field above this checkbox, I have 4 options: TRANSPARENT, FOSCO, PEARL AND METALLIC.

I have a function that if I choose the option "TRANSPARENT", for example, this checkbox above is marked. Except that I need the "FOSCO" and "METALIZADO" options also happen this marking, if it is chosen in the select field. Is there a way to pass more than one id so that the function does not just do the "TRANSPARENT" option?

PHP is the language.

    
asked by anonymous 18.10.2018 / 14:00

1 answer

0

I do not know if I understand your question very well, but if you just check the box when selecting the options TRANSPARENT, FOSCO and METALIZED in the select you can do this:

$('select').on('change', function() {
  var textoVal = $(this).val();           // pega o value de cada option
  if(textoVal == '52' || textoVal == '42' || textoVal == '32') {
    $('input').prop('checked', true);      
  } else {
    $('input').prop('checked', false);
  }
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><divclass="span2" class="checks" >
   <h4>BRANCO</h4>
   <img src= "/images/cor-05.jpg"  width="57" height="27">
   <input type="checkbox" data-id="TRANSPARENTE" name="cor5" value="BRANCO"  />
   <label for="lineatura5">Lineatura<span class="required"></span></label>
   <select class="span6" name="lineatura5" id="lineatura5" value="">
      <option value="">Selecione</option>
      <option value="52">TRANSPARENTE</option>
      <option value="42">FOSCO</option>
      <option value="32">METALIZADO</option>
      <option value="22">PÉROLA</option>
   </select> 
</div>
    
18.10.2018 / 16:11