More than one value in an id variable

Asked

Viewed 41 times

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, FROSTED, PEARL AND METALLIZED.

I have a Function that if you choose the option "TRANSPARENT", for example, this checkbox above is marked. But I need the options "FOSCO" and "METALIZED" also happen this marking, if chosen in the select field. There is a way to pass more than one id so that Function does not just make the option "TRANSPARENT"?

PHP is the language.

  • You want to change the checkbox ID or you want to put more than 1 type ID, TRANSPARENT, FROSTED, METALLIZED?

  • Put more than 1 Victor ID...

  • Enter the code you already have

  • Full code Jrd

  • Why not create input hiddens to do this control? Oh in the item change Js you manipulate these values, cleaning or setting them.

  • I know what you’re talking about, but I can’t perform. I’m a layman yet. I could show you how ?

  • I could, but let me just understand, what is the ultimate purpose of all this??

  • I have four materials to choose from at Select. When "TRANSPARENT", "FROSTED" OR "METALIZED" materials are chosen, the WHITE checkbox should be marked. So my operators will not forget to make the request of this color.

Show 3 more comments

1 answer

0


Cara, I don’t know if I understand your question very well, but if you just check the checkbox when selecting the options TRANSPARENT, MATTE and METALIZED in select you can do so:

$('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>

<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">TRANSPARENTE</option>
      <option value="42">FOSCO</option>
      <option value="32">METALIZADO</option>
      <option value="22">PÉROLA</option>
   </select> 
</div>

  • Exactly that !!!

  • If you have several other checkboxes, it marks as well. How to determine that only the ones I want are marked ?

  • Various ways, give a id for each checkbox, give a name for each checkbox and call so $('input[name='check1']').prop..., can take the check by the father who is the div and call so $('.checks > input') who will only take the check that is inside the div with the class checks and so on.

  • 1

    I had imagined and I did it... it worked super well ;-)

  • Jewel man :). Just one more remark I’ve noticed now in the code. you’re calling two attributes class in the same element here <div class="span2" class="checks" >, when the right would be so <div class="span2 checks" >

  • Thanks for the tip

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.