php - Multi select dropdown - how to add default value -
i'm trying add default value in multiselect dropdown, far tried
<select name="addons[]" multiple="multiple" id="addons"> <option value="not selected" <?php echo set_select('addons[]', 'not selected', true); ?> >not selected</option> <?php foreach ($addons $options) { ?> <option value="<?php echo $options->addon_name; ?>"><h5><?php echo $options->addon_name; ?></h5></option> <?php } ?> </select>
i should suppose default value "not selected" i'm getting empty. 1 knows i'm going wrong ?
<select name="addons[]" multiple="multiple" id="addons"> <option value="not selected" <?php echo in_array("not selected",$addons)?"selected":"" ?> >not selected</option> <?php foreach ($addons $options) { ?> <option value="<?php echo $options->addon_name; ?>" <?php echo in_array($options->addon_name,$addons)?"selected":"" ?> ><h5><?php echo $options->addon_name; ?></h5></option> <?php } ?> </select>
where $addons example $_post['addons'] or array of current addons database.
by way: think should not use < h5 > inside < option > tag
Comments
Post a Comment