Reputation: 223
I have one query result. It has one value called active and the possible values are 'Y' or 'N'. I need to put a check inside html input where the value is 'Y' then I need to put a check on check box. I have attached my code below. Someone please check and correct me.
foreach($list as $key => $values){
$id++;
$active = $values['active'];
//$app_container->assign('checked_flag', $values['active']=='Y' ? 'checked' : '');
$display .= '<tr class="odd">
<td colspan="5">
<table class="dataTable">
<tr>
<td style="width:20%; font-size:12px">'.$values['name'].'</td>
<input type="hidden" data-value="'.$values['id'].'" name ="supply_id" id="supply_id_'.$values['id'].'" value="'.$values['id'].'"/>
<input type="hidden" name="store_id" id ="store_id" value="'.$_POST['store_id'].'" />
<td style="width:20%; text-align:center">
<input type = "checkbox" name = "active_supply" id = "active_supply_'.$values['id'].'" "('.$active.'=="Y") ? "checked" : '';" value = "Y" onclick="saveAction('.$values['id'].' ,'.$_POST['store_id'].')"/>
</td>
</tr>
</table>
</td>
</tr>';
}
This is my php file. and I am hard coding some html file in it.
Upvotes: 0
Views: 40
Reputation: 924
Try to set a variable
$checked = ($active == "Y") ? 'checked="checked"' : '';
change input to this
<input type = "checkbox" name = "active_supply" id = "active_supply_'.$values['id'].'" '.$checked.' value = "Y" onclick="saveAction('.$values['id'].' ,'.$_POST['store_id'].')"/>
Upvotes: 1