1 Reply Latest reply on Aug 22, 2014 6:51 AM by try67

    Cannot get Multiple Checkboxes to behave the way I want.

    RRSmith

      I'm new to JS, and cannot get this to work.  I have a pdf document with four checkboxes.  Of the four check boxes I want to be able to check only one or two of them, and not three or four simultaneously.  Doesn't matter which one or two.

       

      I have this document level function, and I call it from all four boxes as the 'mouse up' action.

       

      //Make sure only Two check boxes are checked

       

      function OnlyTwoP5()

      {

      var CB1 = getField("Check Box1");

      var CB2 = getField("Check Box2");

      var CB3 = getField("Check Box3");

      var CB4 = getField("Check Box4");

       

      //If cb1 & cb2 are checked:   Un-check cb1  if cb3 || cb4

      if ((event.target == CB1 && event.target == CB2 ) &&

          (event.target == CB3 || event.target == CB4)) {

              CB1.value = "Off";

              return; 

          }

         

      //If cb1 & cb3 are checked:   Un-check cb1  if cb2 || cb4

      else if ((event.target == CB1 && event.target == CB3 ) &&

          (event.target == CB2 || event.target == CB4)) {

              CB1.value = "Off";

              return; 

          }

       

      //If cb1 & cb4 are checked:  Un-check cb1  if cb2 || cb3

      else if ((event.target == CB1 && event.target == CB4 ) &&

          (event.target == CB2 || event.target == CB3)) {

              CB1.value = "Off";

              return; 

          }

       

      //If cb2 & cb3 are checked:   Un-check cb2  if cb1 || cb4

      else if ((event.target == CB2 && event.target == CB3 ) &&

          (event.target == CB1 || event.target == CB4)) {

              CB2.value = "Off";

              return; 

          }

       

      //If cb2 & cb4 are checked:  Un-check cb2  if cb1 || cb3

      else if ((event.target == CB2 && event.target == CB4 ) &&

          (event.target == CB1 || event.target == CB3)) {

              CB2.value = "Off";

              return; 

          }

       

      //If cb3 & cb4 are checked:  Un-check cb3  if cb1 || cb2

      else if ((event.target == CB3 && event.target == CB4 ) &&

          (event.target == CB1 || event.target == CB2)) {

              CB3.value = "Off";

          }

      }

       

       

      Any help would be appreciated.

       

      Thank you,

      Randy