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

How to pass "checked" property of a checkbox

I have two "simple" CF pages. The first is an input form page where a user is given, among other things, the option of checking any of 4 check boxes. The second page is a processor page that verifies the data that was entered on the input page. I am trying to have the checked property of each of the 4 checkboxes copied to the processor page so that the user can once again review, or change their selections, if necessary. I can successfully pass the results of the text fields from the input page to the processor page and have those results appear correctly but I am not having luck with the checkboxes. The processor page has cfparam tags set as:
<cfparam name="form.checkbox1" default="">
<cfparam name="form.checkbox2" default="">
<cfparam name="form.checkbox3" default="">
<cfparam name="form.checkbox4" default="">

and the code in tha page where I am "re-displaying" those 4 checkboxes is:

<cfinput type="checkbox" name="checkbox1" value="rp" />Roads<br />
<cfinput type="checkbox" name="checkbox2" value="cl" />Contacting<br />
<cfinput type="checkbox" name="checkbox3" value="se" />Safety<br />
<cfinput type="checkbox" name="checkbox4" value="tp" />Trail<br />

I had assumed that, for example the first checkbox, I could use something like:
<cfinput type="checkbox" name="checkbox1" value="rp" <cfif #form.checkbox1.value# eq "rp">checked="yes"</cfif> Roads />
But that is not working. I have tried various other variations of that theme and still cannot make it work. Might someone offer me some guidance?
Thanks,
Lee
0
lepirtle
Asked:
lepirtle
  • 4
  • 2
1 Solution
 
Andrew MaurerCommented:
This may help show you want is happening...

<cfparam name="form.checkbox1" default="">
<cfparam name="form.checkbox2" default="">
<cfparam name="form.checkbox3" default="">
<cfparam name="form.checkbox4" default="">
 
<cfdump var="#form#">
 
<cfif form.checkbox1 NEQ "">I see number Roads<br /></cfif>
<cfif form.checkbox2 NEQ "">I see number Contacting<br /></cfif>
<cfif form.checkbox3 NEQ "">I see number Safety<br /></cfif>
<cfif form.checkbox4 NEQ "">I see number Trail<br /></cfif>
 
<cfform action="#cgi.SCRIPT_NAME#">
    <cfinput type="checkbox" name="checkbox1" value="rp" />Roads<br />
    <cfinput type="checkbox" name="checkbox2" value="cl" />Contacting<br />
    <cfinput type="checkbox" name="checkbox3" value="se" />Safety<br />
    <cfinput type="checkbox" name="checkbox4" value="tp" />Trail<br />
    <input type="submit" />
</cfform>

Open in new window

0
 
Andrew MaurerCommented:
and if you dont understand what this is doing. copy the code and paste it on a blank cfm page. then call it with your browser
0
 
lepirtleAuthor Commented:
Hi Zadoc,
I tried your solution but it is basically dumping the output on my processing page.

If you go to http://www.leepirtle.com/lib/join/test01ckmemb.cfm and enter some bogus info for the name and address (leave the city blank) and check 1 or more of the 4 check boxes "Road Projects", "Contacting Legislators" etc then press the "pay by check button you will see the result on the "processing page".
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
Andrew MaurerCommented:
Right... so what do you want to do? I gave you an example on how to check for those values
0
 
lepirtleAuthor Commented:
Zadoc,
I didn't see your recommendation about pasting the code into a blank cfm page till I posted the previous entry from you. So I just took your suggestion and can see that the output is(are) text strings depending on which checkboxes are checked but, and perhaps there is something obvious that I am not seeing, but I want the checkboxes themselves to be checked instead of the text strings being displayed.
Thanks,
Lee
0
 
Andrew MaurerCommented:
sorry, my mistake
<cfparam name="form.checkbox1" default="">
<cfparam name="form.checkbox2" default="">
<cfparam name="form.checkbox3" default="">
<cfparam name="form.checkbox4" default="">
 
<cfdump var="#form#">
 
<cfform action="#cgi.SCRIPT_NAME#">
    <input type="checkbox" name="checkbox1" value="rp" <cfif form.checkbox1 NEQ "">checked</cfif> />Roads<br />
    <input type="checkbox" name="checkbox2" value="cl" <cfif form.checkbox2 NEQ "">checked</cfif> />Contacting<br />
    <input type="checkbox" name="checkbox3" value="se" <cfif form.checkbox3 NEQ "">checked</cfif> />Safety<br />
    <input type="checkbox" name="checkbox4" value="tp" <cfif form.checkbox4 NEQ "">checked</cfif> />Trail<br />
    <input type="submit" />
</cfform>

Open in new window

0
 
black0psCommented:
While Form.Checkbox1 NEQ "" works, you can also use:
<cfif IsDefined("Form.Checkbox1")>checked</cfif> but you wouldn't create the Form.Checkbox1 with cfparam.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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