Creating an array of checked checkbox values

Hello.
I have a .cfm page that loops through a stored proc and populates the page with data returned from the query. One of the columns retuned by the query is TransID which is the the primary key of the table. Next to each TransID returned is a checkbox that the user can select. There are 2 forms on my .cfm page - "testArray" and "CorrectRecord". One is inside of the other. The outer form (testArray) is used to gather the TrasnID's of those records where the checkbox has been checked and direct me to another .cfm page where I dump the TransIDs of the array. The inner form is used to capture the TransID in that iteration of the loop and sends it to another .cfm page where I can look at the records in more detail.

Here is my code for this:
<CFSTOREDPROC PROCEDURE="Records" DATASOURCE="SQLServer2005">
<CFPROCRESULT NAME="GetRecords">
</CFSTOREDPROC>

<CFSET TransIDs = ArrayNew(1)>
<CFSET i = ArrayLen(TransIDs) + 1>
                  
<CFFORM action="testArray.cfm" method="POST" name ="testArray">

<CFLOOP query="GetRecords">

<td><div align="center" class="style6"><cfinput type="Checkbox" name="arrayValue" value="# TransID #"></div></td>

<CFSET TransIDs[i] = "#arrayValue#">
                        
     CFFORM action="CorrectRecord.cfm" method="POST" name="CorrectRecord">
     <td><div align="center" class="style6"><input name="Submit" type="submit"class="style9"                  
     value="#TransID#"></td>
     <cfinput type=hidden name="txtClaimControlNo" value="#TransactionID#">
     </CFFORM>

</CFLOOP>

<input type="Submit" name="Submit" value="Resubmit Checked Records">      
</CFFORM>

Problem:
I need to gather the TransID's that the user has selected and store them in an array to pass on to a stored procedure in my database.
When I click on the Submit button for form "testArray", I get an error that #arrayValue# is undefined.
So I tried setting the array (within the loop) equal to the actual value of the TransID as follows:
<CFSET TransIDs[i] = "#TransID#">.
Now this actually takes me to the testArray.cfm page. However, I get a 4 digit number that makes no sense whatsoever when dumping the values. Furthermore, when I click the button inside of the inner form (CorrectRecord), I am still directed to testArray.cfm and I get the same weird number.
I know the machine is doing exactly what Im telling it to do, so can someone pease tell me what Im doing?????? Thanks!
ev72178Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_agx_Commented:
> I get an error that #arrayValue# is undefined.

The field "arrayValue" is a checkbox.  In CF, checkboxes and radio buttons only exist IF they were checked. If they were not checked, you get an "undefined.." message.  Either check that the field exists using the IsDefined() function

<cfif IsDefined("form.arrayValue")>
     the field exists.. do something
<cfelse>
    Sorry. the field does not exist
</cfif>

Or ensure it always exists by using cfparam.  It sets a default value if the field does not already exist

<cfparam name="form.arrayValue" default="">


But you do not really need (2) forms just to redirect a user to pageA.cfm or pageB.cfm depending on what button is clicked.  However, if you do use (2) cfforms I probably would not nest them.  I didn't even know that was allowed ;-)
0
ev72178Author Commented:
1.) You are right - a "nested" form is not allowed. I will fix that later.
2.) I tried putiing <cfparam name = "form.arrayValue" Default=""> in my code and the page loads! However, all of the checkboxes are checked and I don't want this. Also, when I click the Resubmit Checked Records button, I get an error that my array variable is undefined.
0
_agx_Commented:
> a "nested" form is not allowed. I will fix that later.

     That may be related to your problem, so you might consider changing it now.

> all of the checkboxes are checked and I don't want this

    The code you posted does not mark the checkboxes as "checked", so I do not see how
    that could be happening.  Is it possible you omitted some code?

> I click the Resubmit Checked Records button, I get an error that my array variable is undefined.

    Is this a self-posting form (ie posted to the same page)? If not could you post the action page code
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

ev72178Author Commented:
Sorry for the confusion. I have taken out my 2nd form among other changes. Here is my new code:

<CFFORM action="testArray.cfm" method="POST">
<cfparam name = "form.arrayValue" Default="">
                  
<cfloop query="GetUnacceptedRecords">

<td><div align="center" class="style6"><cfinput type="Checkbox" name="arrayValue" value="#TransactionID#"></div></td>

</cfloop>

<cfset TransIDs[i] = '#form.arrayValue#'>
<input type="Submit" name="Submit" value="Resubmit">
</CFFORM>

When I do a <cfdump var=#arrayValue#> on my action page, I get the values I have chosen in a comma delimited list. Rather than trying to create the array from the get go, should I do a list to array? And then I can pass the array to my stored procedure?
Assigning #arrayValue# to my array (TransIDs[i] ) gives me a TransIDs undefined error when I try to dump it.
                        
                        
0
_agx_Commented:
> I get the values I have chosen in a comma delimited list. Rather than trying to
> create the array from the get go, should I do a list to array?

Yes. The reason is you cannot pass an array in a form field the way you're thinking.  

> Assigning #arrayValue# to my array (TransIDs[i] ) gives me a TransIDs undefined
> error when I try to dump it.

I'm not sure what you're trying to do with that part.  The cfparam shold be used on the  action page to avoid an error if none of the checkboxes were checked.  If you just trying to store all of the TransationID's in a hidden field, try using the ValueList(queryName.column) function.  It will create a comma separated list of all values that you can store in a hidden field.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ev72178Author Commented:
Thanks alot for your help, agx.
As far as my comment :
> Assigning #arrayValue# to my array (TransIDs[i] ) gives me a TransIDs >undefined error when I try to dump it.
I was just trying to further explain to you how I was not able to pass an array in a form field as I thougt!
Anyway...here is the code on my action page for anyone interested:




Hopefully other people will find this solution helpful.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.