Link to home
Start Free TrialLog in
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

ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of digitalwise
digitalwise

ASKER

Thank you!
Ahh, I tried to delete the wrong answer :)
I had deleted to much of you CFIFs in the first answer