php - Keep option selected -
i have selectbox values, inserted values inside array.
now want select specific option, , keep option selected when page reloads.
$logos =array('logo1', 'logo2', 'logo3'); echo ' <td class="jofftd"> <label>platform</label> <select name="searchpt"> <option value="0">all</option> '; foreach ($logos $value) { echo ' <option value="'.$value.'">' .$value . '</option> '; } echo ' </select> </td>';
i need this:
foreach ($logos $value) { echo ' <option'; if ($value == $value) echo 'selected="selected"'; echo 'value="'.$value.'">' .$value . '</option> '; }
but doesn't work.
thanks.
assuming using post method form, code (note: not tested)
foreach ($logos $value) { $selected = ($value == $_post['searchpt']) ? ' selected' : ''; echo '<option'. $selected . ' value="'.$value.'">' .$value . '</option>'; }
Comments
Post a Comment