?
Solved

Coldfusion - search form pre-fill

Posted on 2010-08-12
5
Medium Priority
?
476 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 2000 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

AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

Question has a verified solution.

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

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month9 days, 22 hours left to enroll

762 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