For example, I have 3 checkboxes. I want to trigger different events bases on combinations of boxes being checked. For instance, I want an click event triggered on clicking checkbox 1 and a different event based on clicking both checkbox 1 and checkbox 2.
REVISED CODE:
var tSalesPro = document.getElementById("chkSalesPro");
var tSalesProPlus = document.getElementById("chkSalesProPlus");
var tTellerPro = document.getElementById("chkTellerPro");
function checkBoxChecked() {
if (tSalesPro.checked && tSalesProPlus.checked && tTellerPro.checked) {
alert("checkboxes all checked");
}
else if (tSalesPro.checked && tSalesProPlus.checked) {
alert("checkbox 1 & 2 checked");
}
else if (tSalesProPlus.checked && tTellerPro.checked) {
alert("checkbox 2 & 3 checked");
tSalesProPlus.show();
tSalesPro.hide();
tTellerPro.hide();
tSalesProPlus.checked = false;
tTellerPro.checked = false;
}
else if (tSalesPro.checked && tTellerPro.checked) {
alert("checkbox 1 & 3 checked");
tSalesPro.show();
tSalesPro.hide();
tSalesProPlus();
tSalesPro.checked = false;
tSalesProPlus.checked = false;
}
else if (tSalesPro.checked) {
alert("checkbox 1 checked");
tSalesPro.show();
tSalesProPlus.hide();
tTellerPro.hide();
tSalesProPlus.checked = false;
tTellerPro.checked = false;
}
else if (tSalesProPlus.checked) {
alert("checkbox 2 checked");
tSalesProPlus.show();
tSalesPro.hide();
tTellerPro.hide()
tSalesPro.checked = false;
tTellerPro.checked = false;
}
else if (tTellerPro.checked) {
alert("checkbox 3 checked");
tTellerPro.show();
tSalesPro.hide();
tSalesProPlus();
tSalesPro.checked = false;
tSalesProPlus.checked = false;
}
}
tSalesPro.onclick = checkBoxChecked;
tSalesProPlus.onclick = checkBoxChecked;
tTellerPro.onclick = checkBoxChecked;
Below is a simple example of showing how to use javascript and onclick events in order to determine which checkboxes are checked.
Here is an example http://jsfiddle.net/T8YMh/5/