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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Checkboxes for Yes/No in Forms 1

Status
Not open for further replies.

monoone

Programmer
Joined
May 24, 2002
Messages
219
Location
US
Hi;

I have 2 fields in mdb database. Both Field types are Yes/No.

Field Name: MaxPak Type: Yes/No
Field Name:MilPax Type: Yes/No

Here is My CF Page:

SQL------------------

<CFIF IsDefined(&quot;FORM.add&quot;)>
<CFQUERY NAME=&quot;addContact&quot; DATASOURCE=&quot;XPResults&quot; DBTYPE=&quot;ODBC&quot;>

INSERT INTO
XPREQUEST

(MaxPak,MilPak,)

VALUES
('#MacPak#', '#MilPak#')

</CFQUERY>

------Form------------

<FORM ACTION=&quot;index.cfm&quot; METHOD=&quot;post&quot; NAME=&quot;addcontact&quot; id=&quot;addcontact&quot;>

With this form I request <STRONG>one or both</STRONG> of the following (please check the pack(s) you would like):
<BR>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;MacPak&quot; VALUE=&quot;Yes&quot; DEFAULT=&quot;NO&quot;>&nbsp;&nbsp;Macintosh XP Blade Demo Pack - Consisting of MAC 3 & 4.
<BR>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;MilPak&quot; VALUE=&quot;Yes&quot; DEFAULT=&quot;NO&quot;>&nbsp;&nbsp;Miller XP Blade Demo Pack - Consisting of Miller 2 & 3.


<DIV ALIGN=&quot;center&quot;><input type=&quot;submit&quot; name=&quot;add&quot; value=&quot;add&quot;>&nbsp;<input type=&quot;Reset&quot;></DIV>

</FORM>

-------------------------------------------------


This does not work, the error is whacking and I dont think I am doing it right.

Any ideas?

-Eric
 
Here is the error:

Error Diagnostic Information

An error occurred while evaluating the expression:


#MilPak#



Error near line 33, column 6.
--------------------------------------------------------------------------------

Error resolving parameter MILPAK


ColdFusion was unable to determine the value of the parameter. This problem is very likely due to the fact that either:

You have misspelled the parameter name, or
You have not specified a QUERY attribute for a CFOUTPUT, CFMAIL, or CFTABLE tag.


The error occurred while processing an element with a general identifier of (#MilPak#), occupying document position (33:5) to (33:12).
 
What does the error say?
When you say &quot;mdb database&quot;, I assume you mean MS Access. I may be way off, I haven't delt with Access in a while, and I really don't remember how it handles yes/no, but I think if you take the single quotes away from your variables in your insert, (#MacPak#, #MilPak#) instead of ('#MacPak#', '#MilPak#'), it might work. Like I said, though, my Access is a little rusty!

Hope this helps.
 
Got it. You need to scope your variables in your insert statment. Like this: #Form.MacPak# and #Form.MilPak#

Try that.
 
This is wierd...

I changed my access db fields from Yes/No to Text.

Then I Changed my Check Boxes to this:
----------------------------------------------
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;MacPak&quot; VALUE=&quot;Yes&quot;>&nbsp;&nbsp;Macintosh XP Blade Demo Pack - Consisting of MAC 3 & 4.
<BR>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;MilPak&quot; VALUE=&quot;Yes&quot;>&nbsp;&nbsp;Miller XP Blade Demo Pack - Consisting of Miller 2 & 3.
----------------------------------------------

It keeps catch on the MilPak which comes after the MacPak in the SQL.

??
 
Error:
An error occurred while evaluating the expression:


#Form.MilPak#



Error near line 16, column 5.
--------------------------------------------------------------------------------

Error resolving parameter FORM.MILPAK


The specified form field cannot be found. This problem is very likely due to the fact that you have misspelled the form field name.



The error occurred while processing an element with a general identifier of (#Form.MilPak#), occupying document position (16:4) to (16:16).
 
Checkboxes do not get passed if they are not checked, therefore the FORM variables will not exist. You can use cfparam to correct this. Note, 0 is equivalent to NO in your Access YES/NO field. One (1) would be equivalent to YES. The default in this case is 0, or NO.
Code:
<CFIF IsDefined(&quot;FORM.add&quot;)>
<cfparam name=&quot;FORM.MacPak&quot; default=&quot;0&quot; type=&quot;boolean&quot;>
<cfparam name=&quot;FORM.MilPak&quot; default=&quot;0&quot; type=&quot;boolean&quot;>

Code:
<CFQUERY NAME=&quot;addContact&quot; DATASOURCE=&quot;XPResults&quot; DBTYPE=&quot;ODBC&quot;>

INSERT INTO
  XPREQUEST

 (MaxPak,MilPak,)

VALUES
  (#FORM.MacPak#, #FORM.MilPak#)

</CFQUERY>
</CFIF>


-Tek
 
Great thanks!

-Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top