• Resolved Marc_O

    (@marc_o)


    Hello,
    I use the conditional logic of the plugin to show or hide fields in the form regardless of what the user choose but is there a way to do it inside the same checkbox field ?
    Let’s say I have a checkbox field with four choices : A, B, C and D.
    User can choose any field but I don’t want him to choose A and B at the same time.
    Can I hide (ou desactivate) A when and he choose B (and B when he choose A) ?
    Thank you
    Regards

Viewing 1 replies (of 1 total)
  • Thread Starter Marc_O

    (@marc_o)

    Hello,
    Problem solved.
    This is the code for anyone who would like to do the same thing.
    The first two “if” are when the member already choose A or B and the data is in place at the loading of the page, the rest of the code is when the user click on A or B.

    jQuery(function($) {
    if ($('input[value$="A"]').is(":checked")) {
      $('input[value$="B"]')
        .prop("checked", false)
        .prop("disabled", true);
    }
    
    if ($('input[value$="B"]').is(":checked")) {
      $('input[value$="A"]')
        .prop("checked", false)
        .prop("disabled", true);
    }
    
    $('input[value$="A"]').click(function() {
      if ($('input[value$="A"]').is(":checked")) {
        $('input[value$="B"]')
          .prop("checked", false)
          .prop("disabled", true);
      } else {
        $('input[value$="B"]').prop("disabled", false);
      }
    });
    
    $('input[value$="B"]').click(function() {
      if ($('input[value$="B"]').is(":checked")) {
        $('input[value$="A"]')
          .prop("checked", false)
          .prop("disabled", true);
      } else {
        $('input[value$="A"]').prop("disabled", false);
      }
    });
    });
    
Viewing 1 replies (of 1 total)
  • The topic ‘Hide or desactivate a checkbox when another is choose ?’ is closed to new replies.