I'm hoping somebody will be able to set me on the right path to making my code simpler, and I hope my description will suffice.
Here is my query:
When I use many checkboxes on a page, I'd like to know if there is a way to make the array so that I only need to specify the 'true' values, and have a blanket for all other boxes to be 'false'.
In this following example it is easy to get the desired result to get 'message 1' when boxes 1 and 4 are checked, but 2 and 3 remain unchecked; and also 'message 2' then boxes 1, 2 and 4 are checked but box 3 remains unchecked, and then 'message 3' for all other combinations:
{
if(cb[1].checked==true&&cb[2].checked==false&&cb[3].checked==false&&cb[4].checked==true) { alert('message' 1); }
else if(cb[1].checked==true&&cb[2].checked==true&&cb[3].checked==false&&cb[4].checked==true) {alert('message' 2); }
else { alert('message 3'); }
}
But if I have 12 boxes, with a very large total of possible combinations, it would be impractical to use that string, as I need to specify the majority of combinations.
And if I simply use:
{
if(cb[1].checked==true&&cb[4].checked==true) { alert('message' 1); }
else { alert('message 3'); }
}
then the user gets 'message 1' even if he checks, say, box 5 along with boxes 1 and 4.
So, I'd like to know if there is a way to require 'all other boxes' to be unchecked.
Thanks in advance for any ideas.