Can someone help me check my script? It’s not matching and only returns the else.
I want it to alert if less than 10 checkboxes are checked but I can’t get it to work.
I’ve reviewed many of the other similar posts but I can’t see what’s wrong.
This is the most similar to mine but I can’t see how to implement their suggestion:
How to validate a form with multiple checkboxes to have atleast one checked
Full code here:
https://github.com/bignellrp/footyapp
Script:
function validate() {
var checked = 0;
//Reference the Table.
var chks = document.getElementById("remember");
//Loop and count the number of checked CheckBoxes.
for (var i = 0; i < chks.length; i++) {
if (chks[i].checked) {
checked++;
}
}
if (checked > 9) {
return true;
}
else {
alert("Dont you need 10 players?");
return false;
}
};
HTML (running in flask)
<section class="projects-section bg-light" id="projects">
<div class="container">
<!-- Featured Project Row-->
<div class="row align-items-center no-gutters mb-4 mb-lg-5">
<div class="col-xl-4 col-lg-5">
<div class="featured-text text-center text-center">
<form class="text-black-50 mx-auto mt-2 mb-5" method="POST" action="/">
<table class="mx-auto text-lg-left" style="width: 40%">
<colgroup>
<col span="1" style="width: 10%;">
<col span="1" style="width: 30%;">
</colgroup>
<tr>
<td><input type=checkbox name="output_checked" value="Yes"></td>
<td>Admin Only</td>
</tr>
</table>
<input class="btn btn-primary js-scroll-trigger" type="submit">
</form>
</div>
</div>
</div>
</div>
</section>
​
Aucun commentaire:
Enregistrer un commentaire