I have tried to implement a function into my checkbox question where only 3 checkboxes can be checked. However, it will still continue to check beyond the limit (3).
I am certain it has something to do with latestcheck.checked = false;
My typescript function:
factors(whichlist, maxchecked, latestcheck) {
// An array containing the id of each checkbox to monitor.
var listone = new Array("teamStrength", "marketOp", "productOff", "technology", "financialPerform", "coinvestors", "mediaExpo", "awardsWon", "portfolioFit");
// End of customization.
var iterationlist;
eval("iterationlist=" + whichlist);
var count = 0;
for (var i = 0; i < iterationlist.length; i++) {
if ((<HTMLInputElement>document.getElementById(iterationlist[i])).checked == true) {
count++;
}
if (count > maxchecked) {
latestcheck.checked = false;
console.log("last checked: " + latestcheck.checked);
}
}
if (count > maxchecked) {
alert('Sorry, only ' + maxchecked + ' may be checked.');
}
}
What needs to happen is that after the alert pops out, the checkbox that I checked (after the limit of 3, so the fourth checked box) will be unchecked.
Aucun commentaire:
Enregistrer un commentaire