So maybe you can figure out which array index values are NOT selected for deletion, clear out the original array and insert the un-deleted array elements back in there.
On Tue, Jan 12, 2010 at 5:10 PM, Qing Xia <txiasum...@gmail.com> wrote: > Nope, on 2nd thought, Chat was right. If your array index was messed up, > then the error would have occurred sooner while rendering the form. > > I bet the error happens only if item 3 is selected. If you do 1 and 2 then > you'll get the original number 2 remaining in the array. > > On Tue, Jan 12, 2010 at 4:51 PM, Qing Xia <txiasum...@gmail.com> wrote: > >> You are looping over the array sequentially from 1 but are you sure your >> array key values are sequential from 1 as well? >> >> Your loop goes 1, 2, 3, which means it will expect to find >> session.shoppingCart[1].itemid, session.shoppingCart[2].itemid and >> session.shoppingCart[3].itemid. But are you sure those are indeed the key >> values in the session array? If your array key values go 1,3,4 then that >> will definitely break things. >> >> On Tue, Jan 12, 2010 at 4:31 PM, Chad Gray <cg...@careyweb.com> wrote: >> >>> >>> My best guess is if you remove one item it changes the structure of the >>> array and when it goes to remove the next one it cannot be found? >>> >>> Use CFDump to display the array as you are looping over it to help debug. >>> This way you can see the way the array is changing as you are removing >>> items. >>> >>> >>> >>> > -----Original Message----- >>> > From: jrmuniz [mailto:jrmu...@sfsailing.com] >>> > Sent: Tuesday, January 12, 2010 4:16 PM >>> > To: cf-talk >>> > Subject: Problem deleting structure in an array >>> > >>> > >>> > Hello: >>> > >>> > Sorry, I forgot the subject in my last post. >>> > >>> > I'm having an issue deleting a form structure that is in a shopping >>> cart >>> > array. >>> > I'm sure it's something simple I'm doing wrong, but it's driving me >>> crazy. >>> > >>> > I have a checkbox to select which items to delete. >>> > If only one item is selected there is no error and it works fine. >>> > If more than one item is selected then the error is triggered. >>> > Strangely, if I resubmit the form after the error it works OK. >>> > >>> > If I select two items to delete the error is: >>> > The error message is " Element at position [3] doesn't >>> exist in >>> > array" >>> > >>> > Here is the form code: >>> > <cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i"> >>> > <tr> >>> > <td> >>> > <cfinput type="checkbox" value="#i#" name="itemid#i#"> >>> > </td> >>> > <td> >>> > <cfinput type="text" name="quantity#i#" >>> > value="#session.shoppingcart[i].quantity#" size="3"> >>> > </td> >>> > <td> >>> > <cfinput type="text" name="catalogno#i#" >>> > value="#HTMLEditFormat(session.shoppingcart[i].catalog)#" size="10"> >>> > </td> >>> > <td> >>> > <cfinput type="text" name="description#i#" >>> > value="#HTMLEditFormat(session.shoppingcart[i].description)#" >>> > size="40"></td> >>> > <td> >>> > <cfinput type="text" name="price#i#" >>> > value="#session.shoppingcart[i].price#" size="3"> >>> > </td> >>> > </tr> >>> > </cfloop> >>> > >>> > Here is the cfc code: >>> > <cfloop from="1" to="#arrayLen(session.shoppingcart)#" index="i"> >>> > >>> > <cfif StructKeyExists(rc,"itemid" & i)> >>> > <cfset private.temp = arrayDeleteAt(session.shoppingcart,i)> >>> > </cfif> >>> > </cfloop> >>> > >>> > Any help is greatly appreciated. >>> > >>> > Regards, >>> > Jaime >>> > >>> > >>> > >>> > >>> > >>> >>> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329604 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4