Link to home
Start Free TrialLog in
Avatar of cath
cath

asked on

removing items from list using ListDeleteAt...

hi.
I'm having trouble removing items from a list using ListDeleteAt.

I have a list of items held in a session variable (session.choices), then I want to remove some so I output the list with a checkbox next to each record (name="id" value="#id#") and on the following page do this:

// this to remove form.id item(s) from the list

<cfif (len(form.id) GT 0)>
<cfloop list=#FORM.id# index=id>
<cfset sessionchoices = ListDeleteAt(session.choices,
ListFind(session.choices, id))>
</cfloop>
</cfif>

//this to get the fullname of the ones which were deleted, for checking purposes

<cfquery datasource="#dsn#" name="getDeleted">
SELECT fullname
FROM venue_information
WHERE id IN (#form.id#)
ORDER BY fullname
</cfquery>

// this to get fullnames of the items left

<cfquery datasource="#dsn#" name="getRemaining">
SELECT fullname
FROM venue_information
WHERE id IN (#session.choices#)
ORDER BY fullname
</cfquery>

<body...>

<p><b>These are the ones you just deleted:</b><br>
<cfoutput query="getDeleted">#fullname#<br></cfoutput></p>

<p><b>And this is what's left:</b><br>
<br><br>
<cfoutput query="getRemaining">#fullname#<br></cfoutput></p>

however, the output I get is this:

"These are the ones you just deleted:
Brighton Centre
Brighton Dome

And this is what's left:

Brighton Centre
Brighton Dome
Gardner Arts Centre
Georges House Gallery
Komedia
Metropole Galleries"

notice how the onews which are meant to be deleted are still contained in session.choices...

anyone any ideas? I don't get any error message or anything...

TIA

Ian


Avatar of jimmy282
jimmy282
Flag of United Kingdom of Great Britain and Northern Ireland image

try this

<cfif (len(form.id) GT 0)>
<cfloop from="1" to="#listlen("#FORM.id#")#" index=id>
<cfset sessionchoices = ListDeleteAt(session.choices,id)>
</cfloop>
</cfif>
OK,
this is working for me....

<cfset session.choices = "1,2,3,4,5,6">
<cfset form.id="1,2,3">

<cfloop from="1" to="#listlen("#FORM.id#")#" index=id>
<cfset session.choices = ListDeleteAt(session.choices,id)>
</cfloop>

<cfoutput>#session.choices#</cfoutput>

Should work for u too...

Jimmy
ASKER CERTIFIED SOLUTION
Avatar of jimmy282
jimmy282
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cath
cath

ASKER

Doh! that's what comes from staring at it too long ;-)

many thanks - really pleased to have this working.

cheers, Jimmy. You da _man_ ;-)

Ian
Glad I could help!