/    Sign up×
Community /Pin to ProfileBookmark

Disable other checkbox when checkbox is selected

Hello,
I’m sorry I do not know english

I didn’t write the following code
I tried to fix it for myself

How it works
Checkbox3 selected => Checkbox1 and Checkbox2, Disabled, OK, no problem
Checkbox3 unselected => Checkbox1 and Checkbox2, No disabled, OK, no problem

Checkbox1 selected => Checkbox2 Disabled, OK, no problem
Checkbox2 selected => Checkbox2 Disabled, OK, no problem

The problem is here:
Checkbox3 will be active(no disabled) when both Checkbox1 and Checkbox2 are deselected

“`
</head>
<script>
$(document).ready(function(){
$(‘#class1’).on(‘change’, function(){
if($(‘#class1:checked’).length){
$(‘#class3’).prop(‘disabled’, true);
$(‘#class3’).prop(‘checked’, false);
return;
}

$(‘#class3’).prop(‘disabled’, false);
});

$(‘#class2’).on(‘change’, function(){
if($(‘#class2:checked’).length){
$(‘#class3’).prop(‘disabled’, true);
$(‘#class3’).prop(‘checked’, false);
return;
}

$(‘#class3’).prop(‘disabled’, false);
});

$(‘#class3’).on(‘change’, function(){
if($(‘#class3:checked’).length){
$(‘#class1’).prop(‘disabled’, true);
$(‘#class2’).prop(‘disabled’, true);
$(‘#class1’).prop(‘checked’, false);
$(‘#class2’).prop(‘checked’, false);
return;
}

$(‘#class1’).prop(‘disabled’, false);
$(‘#class2’).prop(‘disabled’, false);
});

});
</script>
<body>
<input type=”checkbox” name=”checkbox[]” id=”class1″ value=”Checkbox1″ />Checkbox1
<br />
<input type=”checkbox” name=”checkbox[]” id=”class2″ value=”Checkbox2″ />Checkbox2
<br /><br /><br />
<input type=”checkbox” name=”checkbox[]” id=”class3″ value=”Checkbox3″ />Checkbox3
</body>
“`

http://jsfiddle.net/rgd7hpuq/

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@D_ReadSep 13.2019 — I'm not sure I understand the Problem.

Am I right you want to have Checkbox3 disabled, if Checkbox 1 & 2 are not selected? If so, when should it be selectable? I tried the fiddle and it would never be selectable. Did you think of using radio buttons instead?
×

Success!

Help @gecekule spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...