943,545 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Unsolved
  • Views: 12740
  • ColdFusion RSS
Mar 30th, 2008
0

<cfinput type="checkbox"> Validation

Expand Post »
Hello friends,
I want to validate this two checkbox variables on an action page and also an update page

coldfusion Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoid777 is offline Offline
16 posts
since Feb 2008
Mar 31st, 2008
1

Re: <cfinput type="checkbox"> Validation

You need to specify a value for each one.

For instance:

ColdFusion Syntax (Toggle Plain Text)
  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>.

ColdFusion Syntax (Toggle Plain Text)
  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>
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008
Apr 1st, 2008
0

Re: <cfinput type="checkbox"> Validation

Thanks a lot cmhampton, that was helpful.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoid777 is offline Offline
16 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: <cfquery> Undefined
Next Thread in ColdFusion Forum Timeline: mdf as datasource





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC