Reputation: 553
i have two check boxes that when clicked individually perform there tasks but if both are clicked then there is an other task that should be perform but i am facing an issue.
when i click only 1st check box it should do this. and when i click only 2nd check box it should do this but when i click one and then other and both are checked now do this. i need to do this in jquery
here is the jsFiddle
if(checkbox1) is checkd
{
//do this
}
if(checkbox2) is checkd
{
//do this
}
if(both) are checked do this
here is the html
<input type="checkbox" id="checkbox1" class="kk" />
<input type="checkbox" id="checkbox2" class="kk" />
Upvotes: 1
Views: 175
Reputation: 8726
try this
if ($('#checkbox1').is(':checked') && $('#checkbox2').is(':checked')) {
// if both are checked
}
else if ($('#checkbox1').is(':checked')) {
// if checkbox1 are checked
}
else if ($('#checkbox2').is(':checked')) {
// if checkbox2 are checked
}
Upvotes: 1
Reputation: 2941
Try this code:
var oneChecked = jQuery('#checkbox1').is(':checked');
var twoChecked = jQuery('#checkbox2').is(':checked');
if (oneChecked && twoChecked) {
// both are checked
} else if (oneChecked) {
// checkbox1 is checked
} else if (twoChecked) {
// checkbox2 is checked
} else {
// nothing is checked
}
Upvotes: 2
Reputation: 121998
Try
if($("#checkbox1 input:checked") && $("#checkbox2 input:checked")){
--
}
else if($("#checkbox1 input:checked"){
---
}
else if($("#checkbox2 input:checked"){
---
}else{
-------------nothing checked
}
Upvotes: 1