Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

cfselect preserve selected value on back

Guest
Apr 28, 2011 Apr 28, 2011

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>

2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Apr 30, 2011 Apr 30, 2011

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 variab

...
Translate
Valorous Hero ,
Apr 28, 2011 Apr 28, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 28, 2011 Apr 28, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 30, 2011 Apr 30, 2011
LATEST

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 />

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources