0

I have 2 different checkboxes, one to choose the type of registration and another to choose type of course, both are mandatory. Can someone help me with the function that allows you to select a choice of 2 checkboxes. At this moment I mark one, the other when I'm going to score, uncheck the previous one.

$('input[type="checkbox"]').on('change', function() {
  $('input[type="checkbox"]').not(this).prop('checked', false);

  if ($('#teste').is(':checked')) {
    $('input[type="checkbox"]').is(':checked');
  } else {
    $('#teste').prop('checked', false);
  }
});

HTML -

    <label class="ckbx">
       <input type="checkbox" class="validate[minCheckbox[1], maxCheckbox[1]]" 
         id="geral1" name="tipo[]" value="2" style=" margin-top:15px;">
          <?php if($lng=='pt') echo"Membro da Comissão de Programa, 150 €"?><?php if($lng=='en') echo"Members of Programme Comittee, 150€"?>
     </label> 
  <input type="checkbox" id="teste" class="validate[minCheckbox[1], maxCheckbox[1]]" name="produto[]" value="1">
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57

1 Answers1

0

If you only want to allow one of the two options to be selected. Why not use radiobuttons instead?

If you want to make selecting one of the two options required. See the following link: How to use the "required" attribute with a "radio" input field

The example below will only allow one of the two to be selected.

<input type="radio" name="produto[]" value="1">1<br>
<input type="radio" name="produto[]" value="2">2<br>
Kelvin
  • 320
  • 4
  • 19
  • I want the function to allow me to select the 2 checkboxes. – José Andrade May 24 '19 at 10:39
  • @JoséAndrade Yes, that's exactly what you'll be able to do when you remove that line :) See updated answer for a working example. – Kelvin May 24 '19 at 10:40
  • Yes you already allow me to select options from the 2 checkboxes. But I just want to allow me to select only 1 option from each of the checkboxes, this time allows to select several – José Andrade May 24 '19 at 10:44
  • Now I understand, sorry about that. See updated answer. – Kelvin May 24 '19 at 10:50