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>
          <cfinput type="checkbox" name="gender">

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.

9 Years
Discussion Span
Last Post by zoid777

You need to specify a value for each one.

For instance:

<cfinput type="checkbox" name="gender" value="Male" checked>
      <cfinput type="checkbox" name="gender" value="Female">

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>.

<cfparam name="Form.Gender" default="">

<cfif Form.Gender EQ "Male">
   <!--- Do something --->
<cfelseif Form.Gender EQ "Female">
   <!--- Do something else --->
Votes + Comments
Good work
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.