Show checkbox already marked with jquey according to a MySQL database record


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 everything is fine ).

Calendar image with events already created

Image of the registration form

The user clicking on an already created event will show the records that he has already entered and which is already stored in the database:

Image of the form with the data that the user already registered

Image of the sample of the database, and the assigned field

Jquery code where it shows the information of the events in the inputs:



                //Mostrar la información del evento en los inputs           
                FechaHoraCorreo= calEvent.correo.split(" ");
                FechaHoraInicio= calEvent.inicio.split(" ");
                FechaHoraFin= calEvent.fin.split(" ");
                FechaHoraEntrega= calEvent.entrega.split(" ");


What do I do so that when the user clicks on an event already created, I show the checkboxes already checked according to what the user checked when they registered?

If, for example, you click on Event 1, check out Erick Gaming, or if you click on event 2, show me Andres Medina and Nelson Barrios and so on with the other events that you are creating.

asked by Jairo Arturo Cifuentes 29.08.2018 в 14:54

3 answers


I've already solved it:

It's just doing this and you're done!

                let seleccionados = calEvent.asignados.split(',');

                jQuery(document).ready(function() {
                    seleccionados.forEach(function(nombre) {

answered by 19.09.2018 в 23:31

Try this:

var idEvento = $("#idevento").val();
    data:  idEvento,
    url:   '?URL_retorna_los_asignados_del_evento',  
    type:  'post',
    dataType: "json",
    success:  function (response){ //response es un array
        $('input[type=checkbox]').each(function() {//Recorre los checks
                if(e == $(this).prop("name")){//Asumo el valor del label del check en la propiedad name del check
                    $(this).attr("checked","checked"); // Seteamos los asignados                
answered by 29.08.2018 в 15:58

Just as you are using Jquery to give value to the other fields, you can use the checkedbox's checked property:

$('#idDeTuCheckbox').prop('checked', true);

If you have stored the values of the checkbox, as you have the rest of the fields, it should not be more of a problem.



    $contador = 1;

    foreach ($sql8 as $row) {   ?>
        <input type="checkbox" id="miID-<?php $contador ?>">
        <?php $contador++;
    } ?>

With that you would get to have each of your checkboxes with a different ID. Then you should see how to determine which ones you want to mark or not, depending on how you have stored the checkboxes in your database.

answered by 29.08.2018 в 15:19