how to maintain the selected value of the drop down list after reloading it thrice?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zzzxxxyyy
    New Member
    • Aug 2010
    • 2

    how to maintain the selected value of the drop down list after reloading it thrice?

    i ve 2 dynamic drop down lists... after the user chooses a value in the first drop down ...the second list gets populated..this is done thru reloading... my prob is after reloading it once ,the value in the first list is maintained.... but after reloading it again for another operation... the value in the first list goes blank...only the second one is retained...how do i maintain all the selected values after reloading it thrice ?pls help :(
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I think that you're relying on the browser to retain those "selected" values, which means that using different browsers (and possibly versions) you will get different results. The only way to reliably do this that I can think of is using sessions, but this is a bit overkill for simply retaining values.

    When you "reload" what are you doing? Submitting a form? Pressing refresh? If you're submitting a form, then you could simply check if $_POST['value1'] has been set and set your value1 as that everytime the page loads. If you are hitting refresh, then you're actually asking your browser to reload everything as if you had not been there before, so only server side commands (like sessions) will retain values reliably.

    Comment

    • zzzxxxyyy
      New Member
      • Aug 2010
      • 2

      #3
      Code:
      echo "<SCRIPT language=JavaScript>";
      echo "function reload(form){
      var val=form.cat.options[form.cat.options.selectedIndex].value;
      self.location='dd1.php?cat=' +val;
      }";
      
      echo "</script>";
      m using the above code to reload the form.....so sessions is the best way is it..okie will try ...thanks a lot any way ..will keep askin my doubts :)
      Last edited by Atli; Aug 3 '10, 07:25 AM. Reason: Please use [code] tags for when posting code.

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        No problem. Have you considered using AJAX to only reload parts of the form? Google it if you don't know what I'm talking about, but that only "refreshes" individual code blocks (for example everything in a specific div).

        Comment

        Working...