Link to home
Start Free TrialLog in
Avatar of lepirtle
lepirtle

asked on

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
Avatar of Andrew Maurer
Andrew Maurer
Flag of United States of America image

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

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
Avatar of lepirtle
lepirtle

ASKER

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".
Right... so what do you want to do? I gave you an example on how to check for those values
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
ASKER CERTIFIED SOLUTION
Avatar of Andrew Maurer
Andrew Maurer
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.