DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   ColdFusion (http://www.daniweb.com/forums/forum19.html)
-   -   <cfinput type="checkbox"> Validation (http://www.daniweb.com/forums/thread116400.html)

zoid777 Mar 30th, 2008 3:58 am
<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.

cmhampton Mar 31st, 2008 2:06 pm
Re: <cfinput type="checkbox"> Validation
 
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
<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 --->
</cfif>

zoid777 Apr 1st, 2008 7:43 am
Re: <cfinput type="checkbox"> Validation
 
Thanks a lot cmhampton, that was helpful.


All times are GMT -4. The time now is 4:10 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC