I have a fullcalendar and clicking on some day will show me a form, the user enters the normal data and must select some people assigned to that event with a checkbox. (There all good).
Image with created events: link
Image of the registration form: link
The user clicking on an event will show what he has in the database:
Image of the field assigned in the database: link
As you can see the assignees are: Julian Caicedo and Nelson Barrios, but clicking on an event always shows me the first two checkbox marked osea, Andres Medina and Jhon Cortes and if the database had a single assigned example Nelson Barrios would show me the first checbox that would be Andres Medina.
Image of a record with data from the database: link
Code where I have the checkboxes:
<div class="form-group col-md-12" id="formid">
<label>Asignados:</label>
<?php
$contador = 1;
foreach ($sql8 as $row){
?>
<input type="checkbox" <?php echo 'id="txtAsignados'.$contador.'"' ?> name="txtAsignados[]" class="txtAsignados" value="<?php echo $row['primer_nombre'] . " " . $row['primer_apellido']; $contador++; ?>"><?php echo $row['primer_nombre'] . " " . $row['primer_apellido']; ?>
<?php } ?>
</div>
The counter what it does is concatenate with the id txtAsigandos to have each of the checkboxes a different ID, example txtAsigned1, txtAsigand2 and so on depending on the amount of assigned that exist.
The name of the assignee is taken directly with a query in the database:
$sql8 = mysqli_query($conexion, "SELECT cedula, primer_nombre, primer_apellido, idrol FROM usuario WHERE idrol = 4 ORDER BY primer_nombre ASC");
Jquey code to check the checkbox:
var contaAsig = 1;
var arrayAsig = 0;
var texto = calEvent.asignados;
separador = ",";
textoseparado = texto.split(separador);
for (;textoseparado[arrayAsig];){
$('#txtAsignados'+contaAsig).prop('checked', true);
contaAsig++;
arrayAsig++;
}
What I need is for you to mark the assigned ones and NO the first ones that you always check.