Default checked checkboxes not wanted

Hi,
I have an array of checkboxes which are being checked by default. I don’t want them checked. Can anyone see why they are being checked?

Here is the array,

$examSearch = array ( array ( 'name' => 'AS', 'selected' => 'FALSE'),
                          array ( 'name' => 'AS', 'selected' => 'FALSE'),
                          array ( 'name' => 'A2', 'selected' => 'FALSE'),
                          array ( 'name' => 'GCSE', 'selected' => 'FALSE'),
                          array ( 'name' => 'AP', 'selected' => 'FALSE'),
                          array ( 'name' => 'KET', 'selected' => 'FALSE'),
                          array ( 'name' => 'PET', 'selected' => 'FALSE'),
                          array ( 'name' => 'FCE', 'selected' => 'FALSE'),
                          array ( 'name' => 'IELTS', 'selected' => 'FALSE'));

And here is the HTML

<table class="inner" id="searchTable">
                                         <th>Exam Type:</th>                        
                                          <?php foreach($examSearch as $searchExam): ?>
                                               <tr><td class="left"><input type="checkbox" class="year" id="<?php htmlout($searchExam['name']); ?>" name="exams[]" value="<?php htmlout($searchExam['name']); ?>"
                                                   <?php
                                                    if ($searchExam['selected'])
                                                    {
                                                        echo 'checked';
                                                    }
                                                    ?>><?php htmlout($searchExam['name']); ?></td></tr>
                                          <?php endforeach; ?>
                                    </table>

I thought that since $searchExam[‘selected’] is FALSE what is inside the if statement should not work until a box is checked.

Thanks

you have there the string "FALSE" (which is truthy) not the boolean FALSE.

1 Like

Not sure what this means “truthy”.
Any suggestions how I should proceed?
Thanks

truthy => evaluates as TRUE. see http://php.net/manual/en/types.comparisons.php

don’t define it as string.

1 Like

instead of ‘FALSE’ which is a string use FALSE

1 Like

Yes that is working great now thanks

$examSearch = array ( array ( 'name' => 'AS', 'selected' => FALSE),
                          array ( 'name' => 'A2', 'selected' => FALSE),
                          array ( 'name' => 'GCSE', 'selected' => FALSE),
                          array ( 'name' => 'AP', 'selected' => FALSE),
                          array ( 'name' => 'KET', 'selected' => FALSE),
                          array ( 'name' => 'PET', 'selected' => FALSE),
                          array ( 'name' => 'FCE', 'selected' => FALSE),
                          array ( 'name' => 'IELTS', 'selected' => FALSE));

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.