3
Personal in my form I have 2 distinct groups that have 4 checkbox each. The 1st group is already validated. Which is this: HTML with PHP, it loops with the amount of items in the database:
<?php
$select_funcao = "SELECT * FROM funcao ORDER BY nome";
$result_funcao = mysqli_query($conexao, $select_funcao);
for ($i = 0; $i < mysqli_num_rows($result_funcao); $i++) {
$linha_funcao = mysqli_fetch_array($result_funcao);
?>
<div class="form-check">
<label class="form-check-label" for="<?= $linha_funcao['codigo'] ?>">
<input type="checkbox" class="form-check-input" id="<?= $linha_funcao['codigo'] ?>" name="funcao[]" value="<?= $linha_funcao['codigo'] ?>"><?php echo $linha_funcao['nome'] ?>
</label>
</div>
<?php
}
?>
With that Script
:
<script type="text/javascript">
function validar() {
var i = 0, counter = 0, funcao;
funcao = document.forms[0].elements['funcao[]'];
for (; i < funcao.length; i++) {
if (funcao[i].checked) {
counter++;
}
}
if (counter == 0) {
alert("Selecione pelo menos uma função para essa questão!");
return false;
}
return true;
}
</script>
These 1st checkbox validates right, no problems.
The point is I have another checkbox group:
HTML:
<input type="checkbox" name="correto[]" value="1" class="checkgroup" aria-label="Chebox para permitir input text">
<input type="checkbox" name="correto[]" value="2" class="checkgroup" aria-label="Chebox para permitir input text">
<input type="checkbox" name="correto[]" value="3" class="checkgroup" aria-label="Chebox para permitir input text">
<input type="checkbox" name="correto[]" value="4" class="checkgroup" aria-label="Chebox para permitir input text">
How to validate these above?
Perfect #Sam, vlw
– Aristófanes Melo