www.webdeveloper.com
Results 1 to 4 of 4

Thread: Retaining combo box value when page being reload

  1. #1
    Join Date
    Jun 2007
    Posts
    17

    Smile Returning combo box value when page being reload

    Hi! I have a combo box inside a dynamic table. Each time user make any selection on the combo box the table will be reloaded. How to make sure the combo box is displaying the value previously selected by the user? Is there any javascript properties or method that can handle this situation? Thanks a lot.
    Last edited by yuenli; 08-01-2007 at 01:42 AM.

  2. #2
    Join Date
    May 2007
    Location
    Delhi, India
    Posts
    29

    Lightbulb Try storing it in variables

    If each of your combo-box is in a seperate form on the same page. You can consider storing the selected values in a variable by using GET/POST function in your page.

    Then you can use the same variable for displaying the selected value in your combo-box.

    I hope it would be of some help.

  3. #3
    Join Date
    Jun 2007
    Posts
    17
    Hi! Do you mean that I need to create 2 forms with similar combo box in it with ont of the action is post and another one is get? Then a variable to store the value of selected combo box? This whole thing will work in same page. Thanks.

  4. #4
    Join Date
    May 2007
    Location
    Delhi, India
    Posts
    29

    Thumbs up An example

    Here's one example:
    Code:
    <form id="myForm">
    <select onchange="document.getElementById('myForm').submit()">
    <option value="GET Variable name">"Enter your GET Variable name here so that the value stored it in reflects here."</option>
    <option>---------</option>
    <option>Red</option>
    <option>Blue</option>
    </select>
    <noscript>
    <input type="submit" value="Go" id="mySubmit" />
    </noscript>
    </form>
    
    <form id="myForm2">
    <select onchange="document.getElementById('myForm2').submit()">
    <option>Clothes</option>
    <option>Paint</option>
    </select>
    <noscript>
    <input type="submit" value="Go" id="mySubmit" />
    </noscript>
    </form>

    What else you need to do is to capture the value from the URL using GET method & store it in a variable to use it to display the selected value.

    When form loads for first time your first combo-box would be blank but on reload after selecting a value your GET variable would fill in the blank space & even after reloading you'll get to see the value you selected.

    Further, this way would allow you to inter-link your combo-boxes or, other form methods to use dynamic content like using value from first combo-box to fire an SQL query with the GET variable as one of the conditions & get only the desired results in the next box specific to the selected value above.

    I hope it helps.

    If you're still unsure try googling "Self Submitting Combo-Box". You might get even more lucky.

    Ankit Mathur

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles