Skip to main content
Participating Frequently
December 2, 2010
Answered

Return data from Checkbox for a newbie

  • December 2, 2010
  • 2 replies
  • 1124 views

Here is my input tag:

<cfinput type="checkbox" name="checkbox1" id="box1" value="datafrom1" />

<cfinput type="checkbox" name="checkbox2" id="box2" value="datafrom2"/>

<cfinput type="checkbox" name="checkbox3" id="box3" value="datafrom3" />

Action page:

Is checkbox1 checked #IsDefined("form.checkbox1")#
Is checkbox2 checked #IsDefined("form.checkbox2")#
Is checkbox3 checked #IsDefined("form.checkbox3")#

But all says yes whether the checkbox is checked or not.

I know the answer is simple, but I am very new.


    This topic has been closed for replies.
    Correct answer ilssac

    Thanks Dan.

    I am not a developer, so I'm struggling here:

    I simply want to display what checkboxes were checked, sent to me in an email.

    This is what I have so far:  I receive the information I want except whether any of the various checkboxes were checked.

    What do I use to display the checkbox info

    <cfmail
            from="xxx@dotcom"
            to="xxx@dotcom"
            subject="Subject Application "
            server="">
       
       
        Name: #Trim(FORM.Name)#
        Phone: #Trim(FORM.Phone)#
        Email: #Trim(FORM.Email)#

      </cfmail>


    The easiest and most basic way to *probably* do what you want to do is to name all your checkbox controls the same.

    I.E.

    <input type="checkbox" name="myListOfBoxes" value="Blue"/>

    <input type="checkbox" name="myListOfBoxes" value="Red"/>

    <input type="checkbox" name="myListOfBoxes" value="Green"/>

    Then on the action page.

    <cfparam name="form.myListOfBoxes" default=""> <!--- Easy way to handle if NO checkboxes are selected --->

    <cfoutput>#form.myListOfBoxes#</cfoutput> <!--- Outputs a list of colors selected, empty if none are checked --->

    2 replies

    Participating Frequently
    December 2, 2010

    If you want the actual values:

    Action page:

    checkbox3 = not checked!

    </cfif

    Participating Frequently
    December 2, 2010

    Do you have anything else on the actionpage? CFParams for example?

    Participating Frequently
    December 2, 2010

    yes, it's rather long because there is other data, but yes..should I add this line for each checkbox?

    <cfparam name="FORM.checkbox1" default="">

    Participating Frequently
    December 2, 2010

    if the cfparam for the form is there then it will always be defined.

    So instead you can check for the default value vs the checked value.