March 24th, 2004, 06:56 PM
Help on keeping persistent variables in URL
Can someone please help me with a simple task in cold fusion. Here is what i cannot figure out:
I am trying to write a simple program to do the following:
Display a list of five items for selection. Once that item is selected, dont show it anymore in the list of items to select. Thus, as the items are selected, the page reloads and that item disappears. then you have four items left to select. then you select one of those, then the page reloads and you only have three,etc...
I am storing two name/value pairs in the URL:
the "choice" and the "item viewed". I then pass these variables to the template via the URL scope. The problem i am having is trying to figure out how to sequentially store the "items viewed" in the URL scope so that each time someone selects an item, that is appended to the "item viewed variable in the URL. Unfortunately, each time i do it, i store the current item viewed but lose the prior one.
A typical link that someone clicks on to make a choice is as follows:
<CFIF URL.Choice is 2>
<A HREF="assignment02.cfm?Choice=2">Item 2</A>
I was thinking of something like this:
<CFIF URL.Choice is 2>
<A HREF="assignment02.cfm? Choice=1&ItemsViewed=#URL.ItemsViewed#&1">Item 1</A>
Any ideas? Thanks alot in advance.
March 24th, 2004, 08:21 PM
Use a list and pass it as the URL variable:
<cfparam name="url.selectedItems" value="" />
<cfif not listFindNoCase( url.selectedItems, '1' )>
<a href="thispage.cfm?selectedItems=#listAppend( url.selectedItems, '1' )#">Item 1<a>
<cfif not listFindNoCase( url.selectedItems, '2' )>
<a href="thispage.cfm?selectedItems=#listAppend( url.selectedItems, '2' )#">Item 2<a>
March 24th, 2004, 10:59 PM
hey, thanks alot for the reply, the only thing is, i havent studied that particular deal with the lists. All I have to work with is basic cold fusion tags like: CFIF, CFOUTPUT, CFSET, URL parameters. Got an easier, kindergarten level solution?
March 25th, 2004, 09:39 AM
I suppose you could pass individual url variables, one for each element on the page that you don't want to display. But honestly, that approach is (to me at least) more complicated than using the list appraoch. This is because each link you create will have to know what other selections were also made and include them in the link. With the list you aleady have all of the elements that were picked in one variable.
Lists are very easy to understand, they are just strings with a delimiter (usually commas).