3 Replies Latest reply: Apr 30, 2011 4:24 PM by cfwild RSS

    cfselect preserve selected value on back

    JeffHorne2 Community Member

      We are on CF9.  I have a form that has multiple bound cfselect fields.  If I submit the form and then go back using the browser's back button, all the bound cfselect fields are set back to their initial state.  I have tried used preserveData = "yes" in eth cfform tag and set selected to the field name but this does not seem to work.

       

      Is there a way to achieve this?  Thanks.

       

      Example code:

       

      <cfform id="form1" name="form1" action="majormarketAction.cfm?action=AddRecord" preserveData="yes" method="post">
                <table border="0" cellpadding="4" cellspacing="0" width="480" align="center" class="FormTable">           
                              <tr>
                                  <td style="padding-left:8px;" width="25%" valign="top"><strong>Market</strong><br />
                                  <cfselect name="thisMarketID"
                                      id="thisMarketID"
                                      bind="cfc:/COM/majormarket.getMarketsRemote()"
                                      display="MarketLabel"
                                      value="MarketID"
                                      bindonload="true"
                                      selected="thisMarketID"
                                      class="formText" />
                                  </td>
                                  <td valign="top" colspan="2"><strong>Customer</strong><br />
                                  <cfselect name="CustomerID"
                                      id="CustomerID"
                                      bind="cfc:/COM/majormarket.getCustByMarketRemote({thisMarketID})"
                                      display="CustName"
                                      value="CustomerID"
                                      class="formText"
                                      selected="CustomerID"
                                      style="width:320px;" />   
                                  </td>
                              </tr>

        • 1. Re: cfselect preserve selected value on back
          ilssac Community Member

          JeffHorne2 wrote:

           

          go back using the browser's back button

           

          UNLESS you have configured YOUR browser to ALWAYS request new data from the server when you hit the back button -- OR your web site has requested the browser to do so.  The browser is going to ITS OWN CACHE and showing what it previously downloaded, including the state of all form controls.

           

          In other words, this is most likely a BROWSER issue, NOT a server issue.

          • 2. Re: cfselect preserve selected value on back
            JeffHorne2 Community Member

            Thank you ilssac but fields that are standard select and not bound retain their values.  I have tested it on FF4, ie9, ie6 and Chrome and get the same results.

            • 3. Re: cfselect preserve selected value on back
              cfwild Community Member

              Hi Jeff,

               

              I have found that a SESSION variable works very well in forms that potentially need to use the back button, or even refresh.  If you submit the form the action page can set a SESSION variable for you.  Then if the user hits back, you can test for the existence of a SESSION variable, if it exists, it's populated, if not, it comes up blank.  You can even set the initial variable as a SESSION variable and forget the testing piece.

               

              Having played with html and "hidden" values, a SESSION variable is a very handy piece of code.

               

              Good luck!

               

              <cfwild />