Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFINPUT TYPE CHECKBOX -unable to get value

Status
Not open for further replies.

LongHorn

Programmer
Jun 20, 2001
30
US
If the f_182 is "T", then I want the checkbox to be checked, else uncheck it when this page is displayed the first time.
But the user can change value from T to F or from F to T .
But this final value is not captured in my form. Does anybody know why?
I know that the parameter does not exist if the checkbox is not checked, but my code does not work either way.


<CFFORM ACTION=&quot;#PTH_PROJECT#index.cfm&quot; METHOD=&quot;post&quot;>
<CFIF Trim(ApplDetail.f_182) IS &quot;T&quot;>
<CFINPUT TYPE=&quot;checkbox&quot; NAME=&quot;f_182&quot; VALUE=&quot;T&quot; CHECKED=&quot;Yes&quot;>
<CFELSE>
<CFINPUT TYPE=&quot;checkbox&quot; NAME=&quot;f_182&quot; VALUE=&quot;F&quot; CHECKED=&quot;NO&quot;>
</CFIF>
<INPUT TYPE=&quot;submit&quot; NAME=&quot;cmdSubmit&quot; VALUE=&quot;Submit&quot; WIDTH=&quot;100&quot;>

Thanks,
Longhorn
 
You need to use the same variable name for each checkbox.
That way you'll receive a result either way. Right now your using two different names 'T','F'.

~Dave
 
The thing about checkboxes is that you get no value at all if they aren't checked. In your example, nothing is passed to the next template if both checkboxes are unchecked. And I mean nothing.

Because of this, many people like to use a hidden form field to define a default value. Like:

<INPUT TYPE=&quot;HIDDEN&quot; NAME=&quot;f_182&quot; VALUE=&quot;1&quot;>

Then, using your code above, you can just check for
<CFIF #form.f_182# CONTAINS &quot;T&quot;>
...
<CFELSEIF #form.f_182&quot; CONTAINS &quot;F&quot;>
...
<CFELSE>
...
</CFIF>

Because now, if both are unchecked, you at least have a value of &quot;1&quot;, whereas if &quot;T&quot; is checked, you have a value of &quot;1,T&quot; and if &quot;F&quot; is checked, you have &quot;1,F&quot;.

Hope that helps. John Hoarty
jhoarty@quickestore.com
 
The way I prefer to use checkbox variables is to set the default by using <CFPARAM> tag in the page that is supposed to read it. You could do it like so, then test the existence using #IIF()# in the checkbox.

[COLOR=666666]<!--- Test Only Variables --->[/color]
<CFSET PTH_PROJECT = &quot;&quot;>
<CFSET ApplDetail.f_182 = &quot;F&quot;>

[COLOR=666666]<!--- Set default variable for FORM.f_182 for when it isn't defined --->[/color]
<CFPARAM NAME=&quot;FORM.f_182&quot; DEFAULT=&quot;#ApplDetail.f_182#&quot;>
<CFFORM ACTION=&quot;#PTH_PROJECT#index.cfm&quot; METHOD=&quot;post&quot;>
<CFINPUT TYPE=&quot;checkbox&quot; NAME=&quot;f_182&quot; VALUE=&quot;T&quot;
CHECKED=&quot;#IIF(Trim(FORM.f_182) IS &quot;T&quot;, DE('1'), DE('0'))#&quot;>

[COLOR=000080][COLOR=CC3300]<INPUT TYPE=&quot;submit&quot; NAME=&quot;cmdSubmit&quot; VALUE=&quot;Submit&quot; WIDTH=&quot;100&quot;>[/color][/color]
</CFFORM> - tleish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top