communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "forms" - download "keep selected combobox" - open demo of "keep selected combobox"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

forms - keep selected combobox was created/last modified on Thu 06 May 2004 6:36 PM

often you need to "remember" what a user inputs in a form.
that's not a problem with textfields, but with selectboxes it's a bit harder...
   
<?
   
// you need the values of your combobox in an array
$values = array('us','de','uk','fr','xx');
   
echo
'
   <form method="post" action="'
.$_SERVER['PHP_SELF'].'">
   <select name="country">'
;
   
for(
$x = 0; $x < count($values); $x++)
{
       
// write "selected" if the value matches the one posted
       
if($values[$x] == $_POST['country'])
       {
           
$selected = ' selected';
        }else{
           
$selected = '';
        }
        
// print the option
        
echo '
   <option value="'
.$values[$x].'"'.$selected.'>'.$values[$x].'</option>';
}
   
echo
'
   </select>
   <input type="submit" value="check it out">
   </form>'
;
?>

learn more about some of the PHP functions used in this snippet: array, count, echo, else, for, print

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari