Here is my javascript code, when I clcik the button, if no set is chosen and no check box is marked, the alert window should show both the messages, but at the moment it only show the first one which is “Please check all the box”, what am I doing wrong, thanks!
$('#movetoset').click(function() {
var fail = "";
if ($('#selectsett').val() === 'General') {
fail = "Please chooose a set.\n";
}
for (j = 0; j < array_str_idnum.length; j++) {
if (document.getElementById('check' + array_str_idnum[j]).checked) {
document.getElementById('imagediv' + array_str_idnum[j]).style.display = 'none';
// (Add to database here?)
array_str_idnum[j] = 'flag_gone'; // for example
}
if (document.getElementById('check' + array_str_idnum[j]).checked == false) {
fail = "Please check all the box.\n";
}
}
flag = false;
for (j = 0; j < array_str_idnum.length; j++) {
if (array_str_idnum[j] == 'flag_gone') {
flag = flag && true;
}
else {
flag = false
}
}
if (flag == true) {
$('#steptwo').hide();
$('#begin').fadeIn();
}
if (fail == "") {
return true;
} else {
alert(fail);
return false;
}
});
You need to append to the
failvariable with+=rather than overwriting/reassigning it: