User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 361,943 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,669 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 1494 | Replies: 2
Reply
Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

<cfinput type="checkbox"> Validation

  #1  
Mar 30th, 2008
Hello friends,
I want to validate this two checkbox variables on an action page and also an update page

  1. <cfinput type="checkbox" name="gender"checked>
  2. </label></td>
  3. <td>Female</td>
  4. <td><label>
  5. <cfinput type="checkbox" name="gender">
  6. </label></td>
by default I checked one of them, how can I check if it is checked and what is the best way to store this in the database and have the right checkbox checked when you want to update the form.
Last edited by peter_budo : Mar 30th, 2008 at 5:37 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 54
Reputation: cmhampton is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: <cfinput type="checkbox"> Validation

  #2  
Mar 31st, 2008
You need to specify a value for each one.

For instance:

  1. <cfinput type="checkbox" name="gender" value="Male" checked>
  2. </label></td>
  3. <td>Female</td>
  4. <td><label>
  5. <cfinput type="checkbox" name="gender" value="Female">
  6. </label></td>

When you process the page, the Form.Gender variable will contain either "Male" or "Female" depending on which is checked (or "Male,Female" if both are checked, which can be used as a list incidentally). Make sure to use
<cfif IsDefined("Form.Gender")> before checking for the values, otherwise it will throw an error if none of the checkboxes are checked, unless you've created it with <cfparam>.

  1. <cfparam name="Form.Gender" default="">
  2.  
  3. <cfif Form.Gender EQ "Male">
  4. <!--- Do something --->
  5. <cfelseif Form.Gender EQ "Female">
  6. <!--- Do something else --->
  7. </cfif>
Reply With Quote  
Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

Re: <cfinput type="checkbox"> Validation

  #3  
Apr 1st, 2008
Thanks a lot cmhampton, that was helpful.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 11:40 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC