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.choic es,
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">#fullna me#<br></c foutput></ p>
<p><b>And this is what's left:</b><br>
<br><br>
<cfoutput query="getRemaining">#full name#<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
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.choic
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">#fullna
<p><b>And this is what's left:</b><br>
<br><br>
<cfoutput query="getRemaining">#full
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
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.choic es,id)>
</cfloop>
<cfoutput>#session.choices #</cfoutpu t>
Should work for u too...
Jimmy
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#")#
<cfset session.choices = ListDeleteAt(session.choic
</cfloop>
<cfoutput>#session.choices
Should work for u too...
Jimmy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
many thanks - really pleased to have this working.
cheers, Jimmy. You da _man_ ;-)
Ian
Glad I could help!
<cfif (len(form.id) GT 0)>
<cfloop from="1" to="#listlen("#FORM.id#")#
<cfset sessionchoices = ListDeleteAt(session.choic
</cfloop>
</cfif>