Solved

Coldfusion - search form pre-fill

Posted on 2010-08-12
5
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

726 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