samedi 17 septembre 2016

current selected checkbox to be checked

I have a series of checkbox I want to show the selected checkbox to be check I tried to did this but if I select 2nd 4th and 5th value after submitting form the values are checked in this way

1 Checked 2 Checked 3 Checked 4 5 6

And My selection was

1 2 Checked 3 4 Checked 5 Checked 6

I am unable to judge and get the bug why it is checked in series not what I placed the logic to be checked only those which user have selected

My Code is shown below

<?php
    $i = 0;
    while($model = $sql3->fetch(PDO::FETCH_ASSOC)) {                            
?>
        <input type="checkbox" name="model[]" value="<?php echo $model['model']; ?>" <?php if(isset($_POST['model'][$i]) == $model['model']) { echo "checked"; } ?>> 
        <p><?php echo $model['model']; ?></p>
<?php $i++; } ?>




Aucun commentaire:

Enregistrer un commentaire