Creating an array of checked checkbox values
Posted on 2008-02-12
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">
<CFSET TransIDs = ArrayNew(1)>
<CFSET i = ArrayLen(TransIDs) + 1>
<CFFORM action="testArray.cfm" method="POST" name ="testArray">
<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"
<cfinput type=hidden name="txtClaimControlNo" value="#TransactionID#">
<input type="Submit" name="Submit" value="Resubmit Checked Records">
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!