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

check box won't update in database

Status
Not open for further replies.

zxmax

Technical User
Nov 24, 2003
179
CA
i have a update form, all fields are being updated properly , accept my check box.. in my database, if my check box is checked, it doesn't show in my form that is checked, its always uncheked,

here is my code (related to check box only)

<cfif IsDefined("FORM.MM_UpdateRecord") AND FORM.MM_UpdateRecord EQ "form1">
<cfquery datasource="Evanauto">
UPDATE Usedcars

CarSold=
<cfif IsDefined("FORM.CarSold") AND #FORM.CarSold# NEQ "">
'#FORM.CarSold#'
<cfelse>
NULL
</cfif>
<!--- my form codes --->
<input type="checkbox" name="CarSold" value= "<cfoutput>#recordset1.CarSold#</cfoutput>">

thanks,
 
im not sure i understand your problem, but it seems that your checkbox will never be checked using that code. value= doesn't mean it will or will not be checked, it holds the value for the checkbox if it is checked. you would need to condition the 'checked' attribute.

Code:
<input type="checkbox" name="CarSold" value="YourValue"<cfif recordset1.CarSold EQ 'YourCriteria'> checked</cfif>>
 
The "checked' parameter controls only how the checkbox appears on the form...in other words, if you want the box checked by default, you add "checked' to the tag. But that has nothing to do with processing the form variable.

In the code you showed, your value statement is dynamic, but a checkbox shouldn't be used to hold a dynamic value. It is a simple binary, either it is checked or it is not. So the the value is simple Yes or True. And it is actually irrelvant, because if the box is not checked on submission, the form variable will not even exist at all! So....simply test to see if form.CarSold exists. If it does, the box was checked, and you can set a new variable accordingly. If you need to pass some value, on the other hand, you need another input device, not a checkbox. Hope this helps.

 
PL, you are right, i fooled around with the checkbox, with no results, so what i did, is i made a drop menu witn "yes" and "no" value, and its working just fine,

Thanks, Pl
 
If you wanted a Yes/No value in the db, what you would want to do then is this:

in your form:
<input type="checkbox" name="CarSold" value= "Yes">

In the query:
CarSold=
<cfif IsDefined("FORM.CarSold") AND #FORM.CarSold# NEQ "">
'#FORM.CarSold#'
<cfelse>
'No'
</cfif>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1959-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top