<?PHP
if($events){
foreach($events as $event){ ?>
<tr>
<?php
if($event->ev_ap==1){ $checked="checked";}else{$checked = "";}
?>
<td class="tab_content">
<input type="checkbox" value="<?=$event->event_id?>" <?=$checked?> name="app[]" id="app[]">
</td>
</tr>
Checkbox value not properly checked [closed]
-
31-05-2022 - |
Question
<?php
$i = 0;
foreach($prj_data as $prj_pop) {?>
<input type="checkbox" class="checkbox_project" value="<?php echo $prj_pop->name;?>"
<?php
if($temp_imp[$i]==$prj_pop->name) echo 'checked="true"'; ?>>
<?php //echo $prj_pop->name; ?>
<br><br>
<?php
$i++;
}?>
- Foreach is used for showing the dynamic checkboxes
- Total checkboxes are 4
$temp_imp[$i]
is getting the valuesSchool Children Admission Fee
$prj_pop->name
is also having valuesSchool Children Admission Fee
Actual output to be checkbox to be checked while editing is 2 checkboxes since $i is incremented all the checkboxes are selected. Pls help me with this. The above is my way
Solution
OTHER TIPS
don't use checked="true", but use either just the word checked, or checked="checked"
and as u_mulder said, your comparing 1=1, or always true values, compare against a actual dynamic value.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow