Jump to content

[SOLVED] foearch created select box have post default selected.


Recommended Posts

hey guys i have a select box that i create with an array foreach loop. it is in a form where you can select different options but if you forget to fill something out it take you back to the form with the options filled out.

 

I am having an issue getting the select box to default to what they already had selected.

 

here is my code.

<select name="state" id="dial-up search" tabindex="6" size="1">
             <?php
                foreach ($dailsearch as $key => $value) {
                   if($value == $_POST['state']) {
                        echo ("<option value=\"'$state' selected\">$value</option>\n");
                } else {
                        echo ("<option value=\"$key\">$value</option>\n");
                }
             ?>
                  </select>

 

But it does not seem to work it always reprints the entire option list.  if ya can even just point me in the right direction it would be great.

the spelling was just a typo here. so no issue there but it is still not working. prints the whole option list. not just the previous selected like i want it to.

 

edit

 

i just checked it again and now it does not print anything and i get this error.

 

<b>Warning</b>:  Invalid argument supplied for foreach() in

in the HTML source not printed to the screen

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.

Guest
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.