Forum Moderators: open
function checkAll(cName, status)
{
var theForm = document.getElementById('selectForm');
for (i=0,n=theForm.elements.length;i<n;i++)
if (theForm.elements[i].className.indexOf(cName) !=-1)
{
theForm.elements[i].checked = status;
}
} <form method=post id="selectForm">
Shopping
Food
<span onclick="checkAll('results2', 1);checkAll('results3', 1);checkAll('results4', 1);checkAll('results5', 1);checkAll('results6', 1);checkAll('results7', 1);checkAll('results8', 1);checkAll('results9', 1);checkAll('results10', 1);checkAll('results11', 1);">ALL</span>
<span onclick="checkAll('results2', 0);checkAll('results3', 0);checkAll('results4', 0);checkAll('results5', 0);checkAll('results6', 0);checkAll('results7', 0);checkAll('results8', 0);checkAll('results9', 0);checkAll('results10', 0);checkAll('results11', 0);">NONE</span>
Vegetables
<span onclick="checkAll('results2', 1);">ALL</span>
<span onclick="checkAll('results2', 0);">NONE</span>
<input type="checkbox" value="potato" name="shopping[]" class="results2"> Potato
<input type="checkbox" value="cucumber" name="shopping[]" class="results2"> Cucumber
<input type="checkbox" value="tomato" name="shopping[]" class="results2"> Tomato
Fruit
<span onclick="checkAll('results3', 1);">ALL</span>
<span onclick="checkAll('results3', 0);">NONE</span>
<input type="checkbox" value="orange" name="shopping[]" class="results2"> Orange
<input type="checkbox" value="apple" name="shopping[]" class="results2"> Apple
<input type="checkbox" value="pear" name="shopping[]" class="results2"> Pear
</form> I before could use the class='x' as parameters of my script, it now is impossible.
Vegetables
<span onclick="checkAll('vegetable', 1);">ALL</span>
<span onclick="checkAll('vegetable', 0);">NONE</span>
<input type="checkbox" value="potato" name="shopping[]" class="vegetable"> Potato
<input type="checkbox" value="cucumber" name="shopping[]" class="vegetable"> Cucumber
<input type="checkbox" value="tomato" name="shopping[]" class="vegetable"> Tomato
Fruit
<span onclick="checkAll('fruit', 1);">ALL</span>
<span onclick="checkAll('fruit', 0);">NONE</span>
<input type="checkbox" value="orange" name="shopping[]" class="fruit"> Orange
<input type="checkbox" value="apple" name="shopping[]" class="fruit"> Apple
<input type="checkbox" value="pear" name="shopping[]" class="fruit"> Pear