Hello, I've got another assignment for javascript class that I'm struggling with. Here's the code:
//the check mark boxes
<div id="myboxes">
<p>What do you love?</p>
<p><input name="chocoCake" type="checkbox" value="chocolate cake" /><label for="chocoCake">Chocolate Cake</label></p>
<p><input name="baseball" type="checkbox" value="baseball" /><label for="baseball">Baseball</label></p>
<p><input name="shinyThings" type="checkbox" value="Shiny Things" /><label for="shinyThings">Shiny Things</label></p>
<p><input name="puppies" type="checkbox" value="puppies" /><label for="puppies">Puppies</label></p>
<p><input name="vacation" type="checkbox" value="Vacation" /><label for="vacation"> Vacation</label></p>
<p><input type="button" value="Check All" onclick="checkAll()" /></p>
<p><input type="button" value="Uncheck All" onclick="unCheckAll()" /></p>
</div>
//the javascript
function checkAll() {
var checkboxes = new Array();
checkboxes = document.getElementsByTagName('input');
for (var i = 0; i < checkboxes.length; i++) {
if (checkboxes[i].type == 'checkbox') {
checkboxes[i].setAttribute('checked', true)
}
}
}
function unCheckAll() {
var uncheckboxes = new Array();
uncheckboxes = document.getElementsByTagName('input');
for (var i = 0; i < uncheckboxes.length; i++) {
if (uncheckboxes[i].type == 'checkbox') {
uncheckboxes[i].setAttribute('unchecked', false)
}
}
}
As it stands, the first "Check All" box works great. But, when I use the "Uncheck All" button, nothing happens. What am I missing?