Hello, I have got a select box for a search page and value is coming from database. When i submit the query the value for the select box resets itself to alfabetic order for the next search. What can i do to keep the value which was choosen. <select name="genre"> <?=$cats_form?> </select> Code (markup): Thanks
Hello, You will need to set the SELECTED property of the <option> tag that you require to be selected. Jay
if (isset($valuefromdb)) { echo "<option selected value=\"$valuefromdb\">"; echo "<your other options>"; } else { echo "<all of your options>"; } Code (markup):
you can try something like this; $cats_form = str_replace('<option value="'.$_REQUEST['genre'].'">', '<option value="'.$_REQUEST['genre'].'" selected>', $cats_form); <select name="genre"> <?=$cats_form?> </select> This should work... however, you will need to replace this $_REQUEST['genre'] with some other variable or may be need to use this as it is, it depends on your data flow..