asmith Posted November 25, 2007 Share Posted November 25, 2007 i've used $_SERVER [php_SELF] , so my form and script are just one file . when a user click the submit and have some errors the sript reload again , for a reloaded script i've put :(for exaple) <input type="text" name="username" value=$_POST[username] /> so when it reload the last information the uer has typed won't be delete.it stays. i want to do the same with my "select menu " , i don't know how , the select menu reset when script reload :(example) gender : <select> <option value="">select one</option> <option value="m">male</option> <option value="f">female</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/78775-remaining-value-for-select-option/ Share on other sites More sharing options...
asmith Posted November 25, 2007 Author Share Posted November 25, 2007 figured it out : gender : <select> <option value="$_POST[gender]">select</option> <option value="m">male</option> <option value="f">female</option> </select> but still that select should be somehow removed... :-\ Quote Link to comment https://forums.phpfreaks.com/topic/78775-remaining-value-for-select-option/#findComment-398659 Share on other sites More sharing options...
PHP_PhREEEk Posted November 25, 2007 Share Posted November 25, 2007 I think you may be looking for this: <?php echo "gender : <select> <option value=\"\">select</option> "; if ( $_POST['gender'] == 'm' ) { echo "<option value=\"m\" selected>male</option> "; } else { echo "<option value=\"m\">male</option> "; if ( $_POST['gender'] == 'f' ) { echo "<option value=\"f\" selected>female</option> "; } else { echo "<option value=\"f\">female</option> "; echo"</select>"; ?> PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/78775-remaining-value-for-select-option/#findComment-398690 Share on other sites More sharing options...
xyn Posted November 25, 2007 Share Posted November 25, 2007 Edit: This is a shorter code to PHP_PhREEEk's approach. <? ${"select_".$_POST[gender]} = "selected"; print '<select>'; print '<option value="null" '.$select_null.'>select</option>'; print '<option value="m" '.$select_m.'>male</option>'; print '<option value="f" '.$select_f.'>female</option>'; print '</select>'; Quote Link to comment https://forums.phpfreaks.com/topic/78775-remaining-value-for-select-option/#findComment-398692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.