How can I check a check box with an if?

0

Greetings, I have the following situation:

I have a if that as a target I want to mark a radio button , I have tried with scripts but it does not work for me.

<div class="funkyradio">
<?php
$sql = "SELECT * FROM permiso WHERE user = '" . $object['usuario'] . "' AND fk_actions = '" . $objetoA1['id'] . "';";
$query = $cone->sqlSeleccion($sql);
if (mysqli_num_rows($queryA2) == 1) {
?>
    <script>
        $("#radioA").prop("checked", true);
    </script>
<?php
} else {
?>
    <script>
        $("#radioB").prop("checked", true);
    </script>
<?php
}
?>
<div class="funkyradio-success">
    <input type="radio" name="radio" id="radioA" />
    <label for="radioA">Aprobado</label>
</div>
<div class="funkyradio-danger">
    <input type="radio" name="radio" id="radioB" />
    <label for="radioB">Denegado</label>
</div>

Thanks:)

    
asked by Kevin Delva 24.12.2017 в 22:02
source

2 answers

-1

The solution was to add $(function () {code...} :

<div class="funkyradio">
<?php
$sql = "SELECT * FROM permiso WHERE user = '" . $object['usuario'] . "' AND fk_actions = '" . $objetoA1['id'] . "';";
$query = $cone->sqlSeleccion($sql);
if (mysqli_num_rows($queryA2) == 1) {
?>
<script>
    $(function () {
         $("#radioA").prop("checked", true);
    });
</script>
<?php
} else {
?>
<script>
    $(function () {
        $("#radioB").prop("checked", true);
    });
</script>
<?php
}
?>
<div class="funkyradio-success">
    <input type="radio" name="radio" id="radioA" />
    <label for="radioA">Aprobado</label>
</div>
<div class="funkyradio-danger">
    <input type="radio" name="radio" id="radioB" />
    <label for="radioB">Denegado</label>
</div>

: D

    
answered by 24.12.2017 / 23:01
source
0

It can be solved in a more elegant way and without using Javascript in the following way:

<div class="funkyradio">
<?php
$sql = "SELECT * FROM permiso WHERE user = '" . $object['usuario'] . "' AND fk_actions = '" . $objetoA1['id'] . "';";
$query = $cone->sqlSeleccion($sql); 
$aprobado = mysqli_num_rows($queryA2) == 1;
?>

<div class="funkyradio-success">
    <input type="radio" name="radio" id="radioA" <?php echo $aprobado ? 'checked' : '' ?> />
    <label for="radioA">Aprobado</label>
</div>
<div class="funkyradio-danger">
    <input type="radio" name="radio" id="radioB"<?php echo !$aprobado ? 'checked' : '' ?> />
    <label for="radioB">Denegado</label>
</div>
    
answered by 25.12.2017 в 08:13