If I got your question correctly, then what I have understood is the following:
- When either of the checkboxes is
checked then -: height: 1500px.
- When any two of the checkboxes are
checked then -: height: 2000px.
- When all the three checkboxes are
checked then -: height: 2500px.
- When none of the checkboxes is
checked then -: height is not defined.
Based on this, refer to the demo (only the logic) that I have created.
Please find the code below:
HTML:
<div>
<label>
<input type="checkbox" class="check1" /> Checkbox 1
</label>
<label>
<input type="checkbox" class="check2" /> Checkbox 2
</label>
<label>
<input type="checkbox" class="check3" /> Checkbox 3
</label>
</div>
<p>
</p>
JS:
$(function() {
$('input[type="checkbox"]').on('change', function() {
var isCheck1Checked = $('.check1').prop('checked');
var isCheck2Checked = $('.check2').prop('checked');
var isCheck3Checked = $('.check3').prop('checked');
var text;
if (!isCheck1Checked && !isCheck2Checked && !isCheck3Checked) {
text = '';
} else if (isCheck1Checked && isCheck2Checked && isCheck3Checked) {
text = "The height is 2500px";
} else if ((isCheck1Checked && isCheck2Checked) || (isCheck2Checked && isCheck3Checked) || (isCheck1Checked && isCheck3Checked) && !(isCheck1Checked && isCheck2Checked && isCheck3Checked)) {
text = "The height is 2000px";
} else {
text = "The height is 1500px";
}
$('p').text(text);
});
});
Update : As per request
I have modified the code, which works well on check of every checkbox, it increments a certain value when one, two and three checkboxes are checked, but the decrement.
Refer the demo here.
Code is as follows:
HTML:
<div>
<label>
<input type="checkbox" class="check1" /> Checkbox 1
</label>
<label>
<input type="checkbox" class="check2" /> Checkbox 2
</label>
<label>
<input type="checkbox" class="check3" /> Checkbox 3
</label>
</div>
<br />
<div class="target"></div>
JS:
$(function() {
$('input[type="checkbox"]').on('change', function() {
var isCheck1Checked = $('.check1').prop('checked');
var isCheck2Checked = $('.check2').prop('checked');
var isCheck3Checked = $('.check3').prop('checked');
var text, c = 0;
if (!isCheck1Checked && !isCheck2Checked && !isCheck3Checked) {
text = '';
} else if (isCheck1Checked && isCheck2Checked && isCheck3Checked) {
text = "The height is 2500px";
c = 300;
} else if ((isCheck1Checked && isCheck2Checked) || (isCheck2Checked && isCheck3Checked) || (isCheck1Checked && isCheck3Checked) && !( isCheck1Checked && isCheck2Checked && isCheck3Checked)) {
text = "The height is 2000px";
c = 200;
} else {
text = "The height is 1500px";
c = 50;
}
var oldHeight = parseInt($('.target').css('height'));
$('.target').css('height', oldHeight + c + 'px');
});
});