Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Return data from Checkbox for a newbie

Community Beginner ,
Dec 02, 2010 Dec 02, 2010

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.


808
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Valorous Hero , Dec 03, 2010 Dec 03, 2010

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 sele

...
Translate
Engaged ,
Dec 02, 2010 Dec 02, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2010 Dec 02, 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="">

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 02, 2010 Dec 02, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 02, 2010 Dec 02, 2010

Okay, now I have

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

for each checkbox.

What should my output tag say?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 03, 2010 Dec 03, 2010

The syntax for outputing form variable is

<cfoutput>#form.something#</cfoutput>

What you should output in your particular case depends on what you are trying to accomplish.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2010 Dec 03, 2010

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>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 03, 2010 Dec 03, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 03, 2010 Dec 03, 2010
LATEST

Thanks ilssac!  Works like a charm.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 02, 2010 Dec 02, 2010

If you want the actual values:

Action page:

checkbox3 = not checked!

</cfif

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources