Obtain information from a checkbox on a table

0

I have a table where I fill in the checkbox, before I ask if the user is in a permissions table, in case he finds me he checks the checkbox and if he does not leave it for me. Here my table

<table class="table table-striped" id="dataTable" width="100%" cellspacing="0">

    <tr>
        <th>Opcion</th>

    </tr>
    <?php if($query->num_rows>0):?>
    <?php while ($r=$query->fetch_array()):?>
    <?php $total = mysqli_num_rows(mysqli_query($conn,"SELECT Codigo from Maestro_PerfilUsuarios where Codigo = $persona->Codigo  AND Acceso_CodMenu ='$r[Cod_Menu]'")); ?>
    <tr>
        <?php if ($total==0): ?>
        <td>
            <div class="custom-control custom-checkbox">
                <input type="checkbox" name="permiso[]" value="<?php echo $r[" Cod_Menu "] ?>" class="custom-control-input" id="<?php echo $id.$i; ?>">
                <label class="custom-control-label" for="<?php echo $id.$i; ?>">
                    <?php echo $r["Opcion"] ?></label>
            </div>
        </td>

        <?php else: ?>
        <td>
            <div class="custom-control custom-checkbox">
                <input type="checkbox" name="permiso[]" value="<?php echo $r[" Cod_Menu "] ?>" class="custom-control-input" id="<?php echo $id.$i; ?>" checked>
                <label class="custom-control-label" for="<?php echo $id.$i; ?>">
                    <?php echo $r["Opcion"] ?></label>
                <button type="button" title="Quitar Permiso" name="btn_delete" onclick="QuitarPermiso()" class="close" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
        </td>
        <?php endif; ?>
        <?php $i+=1; ?>
    </tr>
    <?php endwhile;?>
    <?php endif;?>
</table>

Here is my javacritps where I get the text of a td

function QuitarPermiso() {
            $('#dataTable tr').on('click', function() {
                //    var first = $(this).find('td:first').html();
                var first = $(this).find('td:eq(0)').text();
                alert(first);

            });

        }

What I want is to be able to get the value="<?php echo $r[" Cod_Menu "] ?>" of an input on that td, how would I do it?

    
asked by MoteCL 07.08.2018 в 15:23
source

1 answer

1

Depends on the type of input you want to take a value from. Seeing that you use a checkbox, it would be this way.

function QuitarPermiso() {
    $('#dataTable td').on('click', function() {
        var first = $(this).find("input[type=checkbox]").is(":checked")
        alert(first);
    });
}

This would return true or false depending on whether the checkbox is checked or not. However, if you want to save a text string within the value of a checkbox, you can use .val () instead of .is (": checked")

    
answered by 07.08.2018 / 19:56
source