Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Sep 2003
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    selecting list boxes

    Hi all. new to php so bear with me here!

    I am wondering if there is an easy way for php to automatically reselect an item from a list box.

    The purpose is this:
    The user will be filling out a form which, before it gets sent to mysql, I want them to double check what they typed in. I am doing this all in one php page. So the user clicks "submit" and it brings them back to the same form asking them to please double check. Everything then is entered in the form already. Witht he text fields I just set the initial value to be it vvalue in the $_POST array. However, I am not quite sure how to do this with the lsit boxes.

    Can anyone help? Maybe I am goign about this completely the wrong way?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Well to have it re-select what the user chose you would need to check each option like so:

    PHP Code:
    <select name="state">
        <option value="none">Select State</option>
        <option value="AL" <?php if($_POST['state'] == "AL") echo "selected"?>>Alabama</option>
        <option value="AK" <?php if($_POST['state'] == "AK") echo "selected"?>>Alaska</option>
        <option value="AZ" <?php if($_POST['state'] == "AZ") echo "selected"?>>Arizona</option>
        <option value="AR" <?php if($_POST['state'] == "AR") echo "selected"?>>Arkansas</option>
        <option value="CA" <?php if($_POST['state'] == "CA") echo "selected"?>>California</option>
    </select>
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •