简体   繁体   中英

Checkbox check inside html

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.

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'].')"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM