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

Checking dynamically named checkboxes.

Guest
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

I have a form with checkbox fields "Check1", "Check2", "Check3, etc. After submit, I want to loop through to find which are checked. Something like:

cfloop index="1" from="1" to="4"

cfif parameterexists (check#i#)
do stuff
/cfif

/cfloop

Except CF isn't happy with this.
(Yes, I know parameterexists has been deprecated. That's not the problem.)

Do you do this with "evaluate"? What is the right cfif command? Help would be appreciated!

thanks!
B.
TOPICS
Advanced techniques

Views

370

Translate

Translate

Report

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

LEGEND , Sep 17, 2008 Sep 17, 2008
This sort of thing is almost always simpler if you give all your checkboxes the same name but different values. Then you either have a list or nothing at all. You can use isDefined("form.nameofcheckbox") to check.

Votes

Translate

Translate
LEGEND ,
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

This sort of thing is almost always simpler if you give all your checkboxes the same name but different values. Then you either have a list or nothing at all. You can use isDefined("form.nameofcheckbox") to check.

Votes

Translate

Translate

Report

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
Guest
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

Why didn't I think of that? Thanks, Dan!

You wouldn't happen to have the cfif statement to check the box for a certain value handy? I'll google it!

Votes

Translate

Translate

Report

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 ,
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

BrettCPI wrote:

> Do you do this with "evaluate"? What is the right cfif command? Help would
> be appreciated!
>


If you do not go with Dan's suggestion and a single checkbox name with a
list of values you would use array notation and|or structKey exists to
work with this type of data.

<cfif structkKeyExists("form","Check" & i)>
<cfoutput>#form["check" & i]#</cfoutput>
</cfif>

Votes

Translate

Translate

Report

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 ,
Sep 17, 2008 Sep 17, 2008

Copy link to clipboard

Copied

LATEST
use "coldfusion list functions" for your google search string.

Votes

Translate

Translate

Report

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
Documentation