Solved

Coldfusion - search form pre-fill

Posted on 2010-08-12
5
467 Views
Last Modified: 2013-12-24
I'm trying to get my form to remember the last search criteria that was submitted.
I've seen a couple tutorials on this but they were all for your basic text block. My form has drop down lists  and my current code doesnt throw an error but doesnt work either. Example for the minimumPrice field:

<!---prefill form--->
<cfif isDefined("Form.minimumPrice")>
<cfset CLIENT.minimumPrice = Form.minimumPrice>
<cfset prefillminimumprice = Form.minimumPrice>
<cfelseif isDefined("CLIENT.lastminimumPrice")>
<cfset prefillminimumPrice = CLIENT.lastminimumPrice>
<cfelse>
<cfset prefillminimumPrice = " ">
</cfif>
---------------------------------------
and in my form:

<select name="minimumprice">
            <option value="1" selected>#prefillminimumPrice#</option>
            <option value="10000">$10,000</option>
            <option value="25000">$25,000</option>
            <option value="50000">$50,000</option>
            <option value="75000">$75,000</option>
</select>

Any ideas on getting this to work?

Thanks!
0
Comment
Question by:Bang-O-Matic
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33424848
just put the form  either in session variable or localScope. And then when you come back to the page do this

<cfif session.form eq form>selected</cfif>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 33425094
You need to compare the values for each <option> and if the values are the same, mark one as "selected".

<select name="minimumprice">
...
<option value="10000" <cfif YourSavedValue eq 10000>selected</cfif>>$10,000</option>
<option value="25000" <cfif YourSavedValue eq 25000>selected</cfif>>$25,000</option>
....
</select>

... OR if your list is being populated from a query, you could use a cfselect and the "selected" attribute.

<cfform>
        <cfselect name="minimumprice" query="qryPrices" selected="#YourSavedValue#"
             display="PriceTextColumn"
             display="PriceValueColumn" />
</cfform>
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 33445778
Thanks for the help... worked great.
0
 

Author Comment

by:Bang-O-Matic
ID: 33448765
Agx one question, I do have a list being populated from a query, and it's all working great except, now on my form how can I get a blank " " option selected at the top of my list if no savedvalue is selected? Like I have a list of cities populated from a query in my dropdown list and I want my first selected option to be "Any City" if there was no savedvalue for this. example:

          <cfselect name = "city" query = "qryCity" value = "city" selected = "#prefillcity#">        
             <option value=" "></option>
         </cfselect>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33453312
What you have should work. You'd probably want to add the queryPosition="below" attribute too, so the blank options shows up first

<cfselect queryPosition="below" query="qryCity"  ....etc... >       
             <option value=" "></option>
</cfselect>
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
.htaccess rewrite url with querystring problem 13 94
Web server settings related to keepalive 1 121
Coldfusion UNIX/EPOCH Time Conversion - Time Zone? 11 40
REReplaceNoCase help 1 32
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question