Remember the drop down menu selection..! "Side Effect"

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

  1. #1
    Yesterday, I asked how to make the form somehow user friendly by keeping the user's selection in the drop down menu if he has to go back to edit a mistake without having to reselect his country. An expert told me how to solve it & it worked fine BUT it looks like it has a side effect.

    First I will provide the codes then explain what happens.

    <p>
    	Country/region: <select name="Country" > <?php if(isset($_REQUEST['Country'])) { ?>
      <option value="<?php echo $_REQUEST['Country'] ?>" selected="selected"><?php echo $_REQUEST['Country']; ?></option><?php } ?> 
      <option value="CountryA">CountryA</option> 
      <option value="CountryB">CountryB</option> 
      <option value="CountryC">CountryC</option></select></p> 
    Code (markup):
    CASE "1"
    You go to the registration page. You find that CountryA is selected for you...!You can change it but it should not look like that..!

    <p>
    	Country/region: <select name="Country" > <?php if(isset($_REQUEST['Country'])) { ?>
      <option value="<?php echo $_REQUEST['Country'] ?>" selected="selected"><?php echo $_REQUEST['Country']; ?></option><?php } ?> 
      <option >Select Country</option>
      <option value="CountryA">CountryA</option> 
      <option value="CountryB">CountryB</option> 
      <option value="CountryC">CountryC</option></select></p> 
    Code (markup):
    CASE "2"
    I had the idea of adding an option called "Select Country" before Country A. It works fine as when you register you find Select Country & no countries are selected for you BUT if you make an error & you go back to correct it you find "Select Country" as an option to select for your country field.

    I have attached an image of CASE "2" in order to make it clear.
    [​IMG]

    The question is how to make a normal drop down menu without losing the feature of remembering the user selection ?!
     
    gasper000, Jan 11, 2009 IP
  2. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #2
    
    <p>
    	Country/region: <select name="Country" > <?php if(isset($_REQUEST['Country']) && $_REQUEST['Country'] != "Select Country") { ?>
      <option value="<?php echo $_REQUEST['Country'] ?>" selected="selected"><?php echo $_REQUEST['Country']; ?></option><?php } ?> 
      <option >Select Country</option>
      <option value="CountryA">CountryA</option> 
      <option value="CountryB">CountryB</option> 
      <option value="CountryC">CountryC</option></select></p>
    
    PHP:
     
    elias_sorensen, Jan 12, 2009 IP
  3. gasper000

    gasper000 Peon

    Messages:
    55
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    FIXED..!!
    Thank you :)
     
    gasper000, Jan 12, 2009 IP
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    You're welcome.
     
    elias_sorensen, Jan 12, 2009 IP