I have a HTML form and inside it I have a bunch of checkboxes.
What I am trying to do is this.
– If any one checkbox is selected, I want to set a variavle in javascript.
– if nothing is selected, I want to set that variable to blank.
– I am toggling the class of the checkbox as well.
This is how I am currently doing it.
var checklist = "";
$('.form3 :checkbox').change(function() {
$(this).closest('label').toggleClass("checkselected", this.checked);
if(window.checklist != "OL" )
{
window.checklist = "OL";
}
});
The problem with this code is, if once the variable is set, I am not sure how to clear it is the user deselects all checkboxes and none of the boxes are selected any longer.
Any suggestion?
(I am using jQuery)
you might wanna check the number of selected checkboxes.. that way, you would not have a problem. (Well, that is if “OL” does not mean anything…)