dropdown menu not showing up.

Hi there I am new to the forum and if any of you could offer me some help with this it would be great.
I have created a form with a drop down menu, I have the form all setup but one of the requirements is to have the form retain the data upon submitting the form when an error occurs. all the fields are working except the drop down field.

THIS IS THE ENTIRE CODE

echo “”;

            foreach($labels as $field => $label)

            if($field == "state")

{

  echo "<div class='field'><label for='$field'>$label</label>";

              echo"<select name='states'>";

              foreach($state as $value => $stateabr)

              {

   

    echo"<option value='$value'>";

                            if($_POST['states'] == $stateabr)

 {

      echo " selected='selected'";

 }">";

                            echo"$stateabr";

                            echo"</option>";

                            }

                           

                            echo"</select>";

                            echo"</div>";

}

else

{

  echo "<div class='field'><label for='$field'>$label</label>

        <input id='$field' name='$field' type='text' value='".@$$field."'

           size='50%' maxlength='65' /></div>";

}

echo “”;

echo "

      <input type='submit' name='pButton' value='$submit'></div>";

?>

any help would be great.

Hi htp,

The simplest way to accomplish this is to do your form validation with jQuery. You can however do it with PHP.
Here’s how you would basically dot it:

On your “action” script, obtain the value of the selected option and then mark it as the default selection when you are to display again the form along with the error messages.

Sponsor our Newsletter | Privacy Policy | Terms of Service