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

Check Boxes

Status
Not open for further replies.

khurram

IS-IT--Management
Jan 10, 2001
95
CA
Does anyone know how to pass an input type 'checkbox' to a database? Is a bit, integer, etc. Also, How do you use a CFIF statment with it?

For example,

CFIF MailMeInformation EQ CHECKED (This is a complete guess and obviously doesn't work)

Thanks.
 
Hi,
I think this piece of code will help ya:

Index.cfm:

<cfparam name=&quot;chkMarried&quot; default=&quot;0&quot;>

<cfif isdefined(&quot;FrmSubmit&quot;)>
<cfquery datasource=&quot;dsn&quot; query=&quot;q&quot;>
Insert Into Member(Married)
Values(#chkMarried#) <!--- numeric --->
</cfquery>
<cfelse>
<form action=&quot;index.cfm&quot; method=&quot;post&quot;>
Check the box if you are married!<br>
<input type=&quot;checkbox&quot; name=&quot;chkMarried&quot; value=&quot;1&quot;><br>
<input type=&quot;submit&quot; name=&quot;FrmSubmit&quot; value=&quot;Submit&quot;>
</form>
</cfif>


To check the value of the checkbox:

<cfif #chkMarried# is &quot;0&quot;>
...
<cfelse>
...
</cfif>

The value of the checkbox can be (yes/no) instead of (0/1)!! <bebbero></bebbero>
 
The other tricky part is knowing how CF represents &quot;true&quot; and &quot;false&quot; when reading from / writing to the DB.

I suggest:
* use whatever facilities your DB provides to set a Boolean field in a table to &quot;true&quot; in some rows and &quot;false&quot; in others.
* write a test page which lists some of these rows.
* create Application variables which define these values, e.g. <cfset Application.DBTrue = 1>, and in the rest of your code refer to Application variables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top