Coldfusion preFill Form checkbox

Posted on 2014-08-05
Last Modified: 2014-08-05
I know this is easy, but so far I have not been able to get this to work. All I want to do is preFill a checkbox in a cfform.

on my search page I have this checkbox  

<input type="checkbox" name="foreclosure" value="yes">Foreclosure

and when I submit the form to the action page "results" page, I have the same search form there so you can filter results/adjust search query. I want to preFill the checkbox above.

This is what I tried and it doesnt work:

<cfif IsDefined("url.Foreclosure") and len(trim(url.Foreclosure))>
  <cfset form.Foreclosure = url.Foreclosure>

<!---form prefill Foreclosure--->
<cfif isDefined("Form.Foreclosure")>
  <cfset CLIENT.Foreclosure = Form.Foreclosure>
  <cfset prefillForeclosure = Form.Foreclosure>
  <cfelseif isDefined("CLIENT.lastForeclosure")>
  <cfset prefillForeclosure = CLIENT.lastForeclosure>
  <cfset prefillForeclosure = " ">

Can someone tell me where I went wrong?
Thanks! any help is appreciated.
Question by:Bang-O-Matic
    LVL 39

    Accepted Solution

    Don't know what all that stuff is with the client variable and such, I would remove it.
    All you want to do is set the checked attribute if the variable is yes

    <input type="checkbox" name="foreclosure" value="yes" <cfif form.foreclosure is "yes">checked</cfif> >Foreclosure

    Author Closing Comment

    Works perfect....Thank you!!
    LVL 51

    Expert Comment

    (no points...)

    > <cfif IsDefined("url.Foreclosure") and len(trim(url.Foreclosure))>
    >  <cfset form.Foreclosure = url.Foreclosure>

    Nothing to do with your question, but ... is there a reason you need use both the URL and FORM scope? If both pages are search forms (only), just use <form method="GET"...> on both. Then there's no need to copy stuff from the URL to FORM scope.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
    I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    25 Experts available now in Live!

    Get 1:1 Help Now