RE: Trying to keep a dropdown selection sticky

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The selection will stick until you do a form submit.  The most common
practice in PHP is to update the database with the value from the form or at
least save it in a session.  After the update you can redisplay your form
after fetching the DB contents or getting the selection from the session
into a variable (say $choice) and modify the loop below in your form so that
the echo inside the loop is broken into the following;

       foreach ($state_list as $key => $value) {
          echo "<option value=\"$key\"";
          if($key == $choice) echo " selected";		// now it's sticky
;-)
          echo "> $value</option>\n";
       } 

When you fail to indicate which item in a select list is "selected" most
browsers will default to showing the first entry (effectively unsticking
your choice).

Good luck,

Warren Vail

> -----Original Message-----
> From: Michael S. Dunsavage [mailto:mikesd@xxxxxxx] 
> Sent: Friday, July 04, 2008 6:32 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Trying to keep a dropdown selection sticky
> 
> I have a form I want to keep sticky, but I can't figure out 
> how. I got all the <INPUT>'s to be sticky....
> 
> The select script
> 
> 
> <?php
> echo '<strong>State</strong><br>';
> echo '<select name="State">';
> 	foreach ($state_list as $key => $value) {
> 		echo "<option value=\"$key\"> $value</option>\n";
> 	}
> echo '</select>';
> echo '<br>';
> 
> 
> 
> ?>
> 
> 
> so now how do I keep that sticky?
> 
> --
> Michael S. Dunsavage
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux