jim.davidson Posted March 3, 2009 Share Posted March 3, 2009 I have a dropdown menu in a form that list different school types along with an option for other. When other is selected, a text field appears for user input. I got this part to work. The problem is if there was an error somewhere else on the form how do I redisplay the form with that option selected? Also if the user chose 'other' how to I redisplay that text field? Any help will be appreciated. Here's the code <td colspan="3">Type of School <select name="type_of_school" class="text_background" id="type_of_school"onchange="(this.value==7) ? document.getElementById('newSchoolLbl').style.display='' : document.getElementById('newSchoolLbl').style.display='none'"> <option value="">Please Select</option> <?php do { ?> <option value="<?php echo $row_getType_of_school['school_type_id']?>"><?php echo $row_getType_of_school['school_description']?></option> <?php } while ($row_getType_of_school = mysql_fetch_assoc($getType_of_school)); $rows = mysql_num_rows($getType_of_school); if($rows > 0) { mysql_data_seek($getType_of_school, 0); $row_getType_of_school = mysql_fetch_assoc($getType_of_school); } ?> </select> <label style="display:none" id="newSchoolLbl">Enter Your School Type: <input type="text" name="newSchool" class="text_background"> </label> </td> Quote Link to comment https://forums.phpfreaks.com/topic/147777-redisplaying-drop-down-selection/ Share on other sites More sharing options...
ober Posted March 3, 2009 Share Posted March 3, 2009 You have to look at whatever is being passed in the URL. So once you submit, you probably have something like: www.whatever.com/page.php?req=submit&field1=5&field2=blah So in your display of the answer options, you just say: // $current_option would be the value from the row you are entering into the answer options $selected = ""; if($_POST['field2'] == '".$current_option."') { $selected = " selected"; } echo '<option value="'.$row_getType_of_school['school_type_id'].'" '.$selected.'>'.$row_getType_of_school['school_description'].'</option>'; Quote Link to comment https://forums.phpfreaks.com/topic/147777-redisplaying-drop-down-selection/#findComment-775807 Share on other sites More sharing options...
jim.davidson Posted March 4, 2009 Author Share Posted March 4, 2009 Maybe I didn't explain my problem correctly. I'm sure you all have filled a form on line and forgot to enter something. There's nothing more annoying then to have to enter everything over again because you missed on field. So I want to capture everything that was entered and repopulate the fields for the users second attempt to correctly fill the form. I can get everything except for this on condition, that being I have a dropdown list and one of the options on the list is "Other" if the user chooses other then a text field appears and the user enters their description of other. So I need to be able to reload and display what they they entered there if they forgot to enter something in a required field elsewhere. I hope this better explains what I'm trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/147777-redisplaying-drop-down-selection/#findComment-776367 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.