<cfinput type="checkbox"> Validation

Reply

Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

<cfinput type="checkbox"> Validation

 
0
  #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 6:37 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 72
Reputation: cmhampton is an unknown quantity at this point 
Solved Threads: 10
cmhampton's Avatar
cmhampton cmhampton is offline Offline
Junior Poster in Training

Re: <cfinput type="checkbox"> Validation

 
1
  #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 Quick reply to this message  
Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

Re: <cfinput type="checkbox"> Validation

 
0
  #3
Apr 1st, 2008
Thanks a lot cmhampton, that was helpful.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the ColdFusion Forum


Views: 5871 | Replies: 2
Thread Tools Search this Thread



Tag cloud for ColdFusion
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC