thesaleboat Posted September 24, 2008 Share Posted September 24, 2008 How can I get this to go back to option the user selected after the form reloads? This is the only thing that my form currently does not reload when the user has not filled in all fields, which causes the form to show errors and reload with the information the user has already filled in. <span class="mainTextNoIndent"><strong>*Security Clearance:</strong><br/> List current security clearance.</span><br/> <select name="requiredSecurityClearance" id="requiredSecurityClearance" value="<?php echo isset($_POST['requiredSecurityClearance']) ? $_POST['requiredSecurityClearance'] : '';?>" size="1"> <option>None</option> <option>Confidential</option> <option>Secret</option> <option>Top Secret</option> <option>SCI</option> </select> Link to comment https://forums.phpfreaks.com/topic/125637-solved-reload-selected-option-after-form-reloads/ Share on other sites More sharing options...
Vizor Posted September 24, 2008 Share Posted September 24, 2008 It's not the select tag that takes the value option it's the options themselves. For example it should be: <select name="select_box"> <option value="1">1</option> <option value="2">2</option> </select> One way of getting the select box to show the selected option would be to turn the whole select part into a string and then use str_replace to add a selected="selected" attribute. <?php $select = '<select name="select_box"> <option value="1">1</option> <option value="2">2</option> </select>'; $selected_value = '2'; $select = str_replace($selected_value . '">', $selected_value . '" selected="selected">', $select); echo $select; ?> Link to comment https://forums.phpfreaks.com/topic/125637-solved-reload-selected-option-after-form-reloads/#findComment-649585 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Author Share Posted September 24, 2008 Ok, I tried doing this, and it no longer shows up on my form, im sure im just missing something small here. <?php $requiredSecurityClearance= '<select name="requiredSecurityClearance" id="requiredSecurityClearance" size="1"> <option value ="None">None</option> <option value ="Confidential">Confidential</option> <option value ="Secret">Secret</option> <option value ="TopSecret">Top Secret</option> <option value ="SCI">SCI</option> </select>' ?> Link to comment https://forums.phpfreaks.com/topic/125637-solved-reload-selected-option-after-form-reloads/#findComment-649591 Share on other sites More sharing options...
thesaleboat Posted September 24, 2008 Author Share Posted September 24, 2008 alright i guess i will just turn it into another text box? Link to comment https://forums.phpfreaks.com/topic/125637-solved-reload-selected-option-after-form-reloads/#findComment-649723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.