Jump to content

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


synking

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.