Skip to main content
April 1, 2008
Question

index loop with form variables

  • April 1, 2008
  • 2 replies
  • 346 views
I hope this has a really easy answer...

I would like to run this through an index loop 1 to 58, but I can't make the checked understand the nested index variable.

How can I write
<cfloop index="i" from="1" to="58">
<cfif #form.#i## EQ "on"> do this, do that </cfif>
</cfloop>

Any ideas are more than welcome.
This topic has been closed for replies.

2 replies

Inspiring
April 1, 2008
Depending on your requirements, giving them all the same name and values of 1 through 58 could add simplicity and reduce processing time.
Inspiring
April 1, 2008
dazormiq wrote:
> Any ideas are more than welcome.

Array Notation, learn it, love it. It will make you appear all powerful
among your peers.

<cfif form EQ 'on'>...</cfif>

P.S. Your form fields are really just named '1', '2', ... '58'? Not
something like 'myCheckBox_1','myCheckBox_2', etc.?

If they are named in the above common manner, your code would then look
like: <cfif form['myCheckBox_' & i] eq 'on'>...</cfif>

April 1, 2008
I always forget about array notation. That made it work.

For the moment my checkboxes are named 1, 2, 3, ect... I wanted to make it work before I made it pretty.

Thanks tons.