I have a small script on my music player (test site) that is supposed to allow the user to both uncheck (Clear) all the checkboxes or check them all (Select All). The player is located HERE. This is my internal JavaScript:
<script>
function uncheckAll() {
$("input[type='checkbox']:checked").prop("checked", false)
}
function checkAll() {
$("input[type='checkbox']:checked").prop("checked", true)
}
</script>
My input:
<input type="button" onclick="uncheckAll()" value="Clear"/><input class="check" type="button" onclick="checkAll()" value="Select All"/>
The Clear button functions well. The Select All button does not function.
I wondered if the problem is my internal Javascript or could it have something to do with the fact that the player's natural default is to open with all the boxes checked? (The purpose for the Select All button is just to return the checks to their natural position if the user decides to hear all the songs, after all, instead of a few select ones. I realize that the user could just refresh the page, but I thought the Select All button would be more user friendly.
(The player's JavaScript, ttw-music-player.js, has its location link within the page source's head tags.) Sections that deal with the checkboxes are:
markup = {
listItem:'<li class="track">' +
'<span class="title"></span>' +
'<span class="duration"></span>' +
'<span class="rating"></span>' +
'<a href="#" class="buy not-active" target="_blank"></a>' +
'<input class="cb" type="checkbox" checked="true">' +
'</li>',
ratingBar:'<span class="rating-level rating-bar"></span>'
};
and
function playlistNext() {
$cbs = $(".cb");
var index = current;
do {
index = (index + 1 < myPlaylist.length) ? index + 1 : 0;
} while (!$cbs.eq(index).prop("checked"));
playlistAdvance(index);
}
Can anyone help me determine why the Select All (checkAll) function does not work, while the Clear (uncheckAll) function does?