• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 293
  • Last Modified:

Coldfusion preFill Form checkbox

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

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


Can someone tell me where I went wrong?
Thanks! any help is appreciated.
0
Bang-O-Matic
Asked:
Bang-O-Matic
1 Solution
 
gdemariaCommented:
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
0
 
Bang-O-MaticAuthor Commented:
Works perfect....Thank you!!
0
 
_agx_Commented:
(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.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now