#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0

    Talking 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>

    <CFELSE>
    <A HREF="assignment02.cfm?Choice=2">Item 2</A>
    </CFIF>


    I was thinking of something like this:

    <CFIF URL.Choice is 2>

    <CFELSE>
    <cfoutput>
    <A HREF="assignment02.cfm? Choice=1&ItemsViewed=#URL.ItemsViewed#&1">Item 1</A>
    </cfoutput>

    Any ideas? Thanks alot in advance.

    jay wilner
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    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>

    <cfif not listFindNoCase( url.selectedItems, '2' )>
    <a href="thispage.cfm?selectedItems=#listAppend( url.selectedItems, '2' )#">Item 2<a>
    </cfif>

    etc...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    2
    Rep Power
    0

    too complicated


    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?
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,265
    Rep Power
    968
    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).

IMN logo majestic logo threadwatch logo seochat tools logo