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

Check Box Problem 12

Status
Not open for further replies.

bmacman

IS-IT--Management
Feb 19, 2001
51
0
0
US
I have a page that I am trying to use checkboxes and then update a database with the criteria from the checkboxes. The problem is: When all boxes are checked, the tables in the DB are updated correctly. However, when I uncheck one of the check boxes I get an error that states the following:
Error Diagnostic Information

An error occurred while evaluating the expression:
"#form.irw#"
Error near line 23, column 17.

Below is the code in the page where I am having the problems.

<cfparam name=&quot;#form.telco#&quot; default=&quot;0&quot;>
<cfif #form.telco# is &quot;1&quot;>
<cfquery name=&quot;telcorequest&quot; datasource=&quot;teradata32&quot; username=&quot;username&quot; password=&quot;password&quot;>
insert into C_U_V.VCCRB044_USER_QUEST_VALIDATE
(USER_ID, UNV_REQUESTED)
VALUES ('#FORM.SBCID#','TELCO')
</cfquery>
</cfif>

<cfparam name=&quot;#form.irw#&quot; default=&quot;0&quot;>
<cfif #form.irw# is &quot;1&quot;>
<cfquery name=&quot;irwrequest&quot; datasource=&quot;teradata32&quot; username=&quot;username&quot; password=&quot;password&quot;>
insert into C_U_V.VCCRB044_USER_QUEST_VALIDATE
(USER_ID, UNV_REQUESTED)
VALUES ('#FORM.SBCID#','IRW')
</cfquery>
</cfif>

<cfparam name=&quot;#form.orw#&quot; default=&quot;0&quot;>
<cfif #form.orw# is &quot;1&quot;>
<cfquery name=&quot;orwrequest&quot; datasource=&quot;teradata32&quot; username=&quot;username&quot; password=&quot;password&quot;>
insert into C_U_V.VCCRB044_USER_QUEST_VALIDATE
(USER_ID, UNV_REQUESTED)
VALUES ('#FORM.SBCID#','ORW')
</cfquery>
</cfif>

Any help on this would greatly be appreciated
 
because an unchecked checkbox isn't passed to the next page. So instead of <cfif #form.irw# is &quot;1&quot;> you'd better use <cfif isdefined(&quot;form.irw&quot;)>. And this will work ! (let me know if it doesn't ... but it should !)
 
I think you just need to change

<cfparam name=&quot;#form.irw#&quot; default=&quot;0&quot;>

to

<cfparam name=&quot;form.irw&quot; default=&quot;0&quot;>

When you use &quot;#form.irw#&quot;, you are telling CF to take the value of the form variable irw and pass it to cfparam. Since it doesn't exist, you get an error. What you really want is to give cfparam a string that contains the name of the variable, not the actual variable.

Hope this helps,
GJ
 
You're absolutely right, GunJack. I was just dealing with the same problem, and your tweak worked instantly. Though the unchecked checkbox's value isn't passed, the name is ...
Thanks to you too, iza.
 
Now here's a follow-up question. I'm trying to unckeck a checkbox (yes/no) field in my database by using a hidden field with the value of 0 (or No or FALSE; I tried them all.) However, the database is not unselecting the checkbox in the database. I've tried with both CFUpdates and SQL Updates but neither work. Could this be due to a similar reason as these other problems?

FTK
 
Updating a Yes/No field (in Access 2000 anyway) to 0 (zero) will uncheck the box.

<cfquery datasource=&quot;#datasource#&quot;>
UPDATE tableName
SET fieldname = 0
WHERE condition
</cfquery>

That'll do it.

Also, checkboxes do not pass either their name or a value when not checked UNLESS you set a default value for them, as in <cfparam name=&quot;form.checkboxName&quot; default=&quot;0&quot;>. You can also use <input type=&quot;Hidden&quot; name=&quot;checkboxName&quot; value=&quot;0&quot;>. Then in the form, use <input type=&quot;checkbox&quot; name=&quot;checkboxName&quot; value=&quot;1&quot;>. In the latter case, if the checkbox is checked, the passed value will be &quot;0,1&quot; and if not, the passed value will just be &quot;0&quot;. You can check for it's state (checked, unchecked) on the result page using:
<cfif #form.checkboxName# CONTAINS &quot;1&quot;>
action
<cfelse>
other action
</cfif>

and then later (on result page), test for existence by:


John Hoarty
jhoarty@quickestore.com
CFDJ Readers Choice Awards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top