On Sat, 2008-07-05 at 21:30 +1000, Peter Jackson wrote: > Michael S. Dunsavage wrote: > > 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>'; > > > > > > > > ?> > > > > If I'm reading this correctly you mean if the value has been selected > before select it again? > If so way I did it was by checking the database value > eg > echo "<option value=\"$key\" > if ($row[id] == $key) { > print "SELECTED"; } > echo "> $value </option>\n"; > > Peter Jackson What I mean is when the users clicks submit, and the form is handled and some information is lacking, it retains what information was given. What I eventually did was: foreach($state_list as $key=>$value){ if($selected_state == $key){ $sel = 'selected="selected"'; } else{ $sel = ''; } echo "<option $sel value=\"$key\">$value</option>"; } echo '</select>'; ?> And then put if (!empty($_POST)) { $selected_state = $_POST['State']; } At the beginning of the scripts. Full script: <?php if (!empty($_POST)) { $selected_state = $_POST['State']; } if (isset($_POST['SUBMIT'])) { // Handle the form. $message = NULL; // Create an empty new variable. // Check for a name. if (strlen($_POST['FirstName']) > 0) { $FirstName = TRUE; } else { $FirstName = FALSE; $message .= '<p>You forgot to enter your first name.</p>'; } if (strlen($_POST['LastName']) > 0) { $LastName = TRUE; } else { $LastName = FALSE; $message .= '<p>You forgot to enter your last name.</p>'; } // Check for an email address. if (strlen($_POST['Email']) > 0) { $Email = TRUE; } else { $Email = FALSE; $message .= '<p>You forgot to enter your email address.</p>'; } //Check for Address if (strlen($_POST['Address']) > 0) { $Address = TRUE; } else { $AddreSS= FALSE; $message .= '<p>You forgot to enter your address.</p>'; } //Check for City if (strlen($_POST['City']) > 0) { $City = TRUE; } else { $City = FALSE; $message .= '<p>You forgot to enter your city.</p>'; } //Check for Zip if (strlen($_POST['Zip']) > 0) { $Zip = TRUE; } else { $Zip = FALSE; $message .= '<p>You forgot to enter your zip code.</p>'; } //Check for Comments if (strlen($_POST['Comments']) > 0) { $Commentsbody=$_POST['Comments']; $Comments = TRUE; } else { $Comments = FALSE; $message .= '<p>You forgot to enter any comments.</p>'; } if ($FirstName && $LastName && $Email && $Address && $City && $Zip && $Comments) { // If everything's okay. // Register the user. // Send an email. $body = "Your comments were: \n\n ' $Commentsbody ' \n\n We will repsond to your e-mail shortly.\n\nSincerely,\nMSD Computing"; mail ($_POST['Email'], 'Thank you for contacting MSD Computing.', $body, 'From: admin@xxxxxxxxxxxxxxxx'); header ('Location: thankyou.php'); exit(); } else { $message .= '<p>Please try again.</p>'; } } $page_title="Contact MSD Computing"; include ('../phpinclude/header.inc'); if (isset($message)) { echo '<strong></strong><font color="#9B1003" size=4>', $message, '</font></strong>'; } ?> -- Michael S. Dunsavage -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php