Jump to content

redisplaying drop down selection


Recommended Posts

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);  } ?>


            <label style="display:none" id="newSchoolLbl">Enter Your School Type: <input type="text" name="newSchool" class="text_background">



Link to comment
Share on other sites

You have to look at whatever is being passed in the URL.  So once you submit, you probably have something like:




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>';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.