Avatar of digitalwise
digitalwise
 asked on

Re-enable disabled checkboxes not working.

We have some jquery that disables checkboxes if a certain value of the group is checked.  That works great but if you uncheck the disabling checkbox, it isn't re-enabling all of them.  

$("input[name$='mp_speccap']").click(function() {
        if ($(this).val()=="None of these")  {
          $(".speccap").prop('disabled', true);
          $(".speccap2").prop('disabled', true);
          

      }
      else if ($(this).val()=="I don’t know")  {
          $(".speccap").prop('disabled', true);
          $(".speccap1").prop('disabled', true);
      }
        
       else   {
         $(".speccap").prop('disabled', false);
           $(".speccap1").prop('disabled', false);
          $(".speccap2").prop('disabled', false);
      }
    });

Open in new window

This is the checkbox set


<input type="checkbox" name="mp_speccap" class="speccap" value="Aviation" <cfif getapp.mp_speccap contains "Aviation">checked</cfif> <cfif getapp.mp_speccap is "None of these" or getapp.mp_speccap is "I don’t know">disabled</cfif>> Aviation<br>
<input type="checkbox" name="mp_speccap"  class="speccap" value="Embassy duty" <cfif getapp.mp_speccap contains "Embassy duty">checked</cfif> <cfif getapp.mp_speccap is "None of these" or getapp.mp_speccap is "I don’t know">disabled</cfif>> Embassy duty<br>
<input type="checkbox" name="mp_speccap"  class="speccap" value="EOD (Explosive Ordnance Disposal)" <cfif getapp.mp_speccap contains "EOD (Explosive Ordnance Disposal)">checked</cfif> <cfif getapp.mp_speccap is "None of these" or getapp.mp_speccap is "I don’t know">disabled</cfif>> EOD (Explosive Ordnance Disposal)<br> <input type="checkbox" name="mp_speccap"  class="speccap" value="MARSOC (Marine Corps Special Operations Command)" <cfif getapp.mp_speccap contains "MARSOC (Marine Corps Special Operations Command)">checked</cfif> <cfif getapp.mp_speccap is "None of these" or getapp.mp_speccap is "I don’t know">disabled</cfif>> MARSOC (Marine Corps Special Operations Command)<br> <input type="checkbox" name="mp_speccap"  class="speccap" value="RECON (Reconnaissance) or Force RECON" <cfif getapp.mp_speccap contains "RECON (Reconnaissance) or Force RECON">checked</cfif> <cfif getapp.mp_speccap is "None of these" or getapp.mp_speccap is "I don’t know">disabled</cfif>> RECON (Reconnaissance) or Force RECON<br> <input type="checkbox" name="mp_speccap"  class="speccap1" value="None of these" <cfif getapp.mp_speccap contains "None of these">checked</cfif> <cfif getapp.mp_speccap is "I don’t know">disabled</cfif>> None of these<br> <input type="checkbox" name="mp_speccap"  class="speccap2" value="I don’t know" <cfif getapp.mp_speccap contains "I don’t know">checked</cfif> <cfif getapp.mp_speccap is "None of these">disabled</cfif>> I don’t know<br>

Open in new window

jQuery

Avatar of undefined
Last Comment
Michel Plungjan

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Michel Plungjan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

So this works

https://jsfiddle.net/mplungjan/esLft1ba/

$("input[name$='mp_speccap']").click(function() {
  const dis1 = $(".speccap1").is(":checked")
  const dis2 = $(".speccap2").is(":checked")
  $(".speccap").prop('disabled', dis1 || dis2);
  $(".speccap1").prop('disabled', dis2);
  $(".speccap2").prop('disabled', dis1);
});

Open in new window

digitalwise

ASKER
Thank you!
Michel Plungjan

Ahh, I tried to delete the wrong answer :)
I had deleted to much of you CFIFs in the first answer
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes