Remember the drop down menu selection..!

Discussion in 'PHP' started by gasper000, Jan 10, 2009.

  1. #1
    I have a form that asks the user to enter his country...What I want to know is how to remember the user's country selection if he was returned back to the registration page due to an error he made during the registration in a different field without asking him again to select his country.

     <p>
    	Country: <select name="Country"> 
      <option value="" selected="selected">Select Country</option> 
      <option value="whatever1">whatever1</option>
      <option value="whatever2">whatever2</option>
      <option value="whatever3">whatever3</option>
      <option value="whatever4">whatever4</option>
     </select>
    Code (markup):
    I use the following code to do the same thing when it's a text field but I don't know how to do it when it's a selection field.
    	value="<?php if(isset($trimmed['whatever'])) echo
    	$trimmed['whatever']; ?>" />
    Code (markup):
    any ideas ?
     
    gasper000, Jan 10, 2009 IP
  2. manjifera

    manjifera Well-Known Member

    Messages:
    232
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    118
    #2
    <option value="<?php echo "$_REQUEST['seleted_coun_val"]; ?>" selected="selected"><?php echo "$_REQUEST['seleted_coun_val']; ?></option>
     
    manjifera, Jan 10, 2009 IP
    gasper000 likes this.
  3. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you..it did work but needed a small syntax correction.:)

    value="<?php echo $_REQUEST['whatever'] ?>"  selected="selected"><?php echo $_REQUEST['whatever']; ?></option> 
    Code (markup):
     
    gasper000, Jan 10, 2009 IP