I am having some difficulties when trying to iterate all checkbox and check if it is checked. Here is the code:
content = "<table class=\"filter-table\">";
content += "<tr><td><input class=\"pssLabel\" type=\"checkbox\" onclick=\"toggleOverlayer('pssLabel')\">Show Label</td></tr>" +
"<tr><td><div id=\"pss\"></div></td></tr>";
content += "<tr><td colspan=\"2\" style=\"padding:5px;font-size:15px;color:black;\">Development Type</td></tr>";
content += "<tr><td><input value='Commercial and Residential' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()' >Commercial and Residential</td><td><input value='Commercial' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()' >Commercial</td></tr>";
content += "<tr><td><input value='Heavy Vehicle Park' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Heavy Vehicle Park</td><td><input value='Hospital' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Hospital</td></tr>";
content += "<tr><td><input value='Hotel' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Hotel</td><td><input value='Industrial' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Industrial</td></tr>";
content += "<tr><td><input value='Industrial-White' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Industrial-White</td><td><input value='Office' class=\"pssCheckBox\" type=\"checkbox\" onclick='queryPSS()'>Office</td></tr>";
Here is how I iterate all checkbox and perform checking:
function queryPSS() {
var type_filter = new Array();
//Iterate thru all checkbox
$(":checkbox").each(function(index, element) {
if($(this).is(':checked'))
{
type_filter.push($(this).val());
}
});
}
However, is there any way for me to skip the first checkbox (no matter checked or not) and check for other checkbox and store into array.
Thanks in advance.
.each()callback is theindexargument which will let you test if it's the first checkbox or not. You could also use a common class name on the checkboxes that you do want to iterate and just query on that class name instead.