954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

<cfinput type="checkbox"> Validation

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

<cfinput type="checkbox" name="gender"checked>
        </label></td>
        <td>Female</td>
        <td><label>
          <cfinput type="checkbox" name="gender">
        </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.

zoid777
Newbie Poster
16 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

You need to specify a value for each one.

For instance:

<cfinput type="checkbox" name="gender" value="Male" checked>
      </label></td>
      <td>Female</td>
      <td><label>
      <cfinput type="checkbox" name="gender" value="Female">
      </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
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 name="Form.Gender" default="">

<cfif Form.Gender EQ "Male">
   <!--- Do something --->
<cfelseif Form.Gender EQ "Female">
   <!--- Do something else --->
</cfif>
cmhampton
Junior Poster in Training
79 posts since Feb 2008
Reputation Points: 23
Solved Threads: 10
 

Thanks a lot cmhampton, that was helpful.

zoid777
Newbie Poster
16 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You