set session when image clicked

Discussion in 'Programming' started by roisinD, Apr 13, 2007.

  1. #1
    hi, i'm pretty new to coldfusion and am having a small problem, basically i have a page which has thumbnail images of different characters, i want to set a session depending on which image is clicked, but if another thumbnail is clicked i want it to reset the session to equal something else, any ideas? this is the code i'm using at the moment in the img tag

    onClick="<cfset session.animal = "leo">"

    it is setting a session but it doesn't override the session if another thumbnail is clicked:
     
    roisinD, Apr 13, 2007 IP
  2. IsRoss()

    IsRoss() Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello riosinD

    You should always lock the scope when setting or resetting session or application variables.

    <cflock scope="session" type="exclusive" timeout="30"><cfset session.animal = "leo"></cflock>

    Give that a try and see if it resolves the issue...
     
    IsRoss(), Apr 13, 2007 IP
  3. roisinD

    roisinD Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi i'v tried replacing my code with yours but it's still coming back with a problem, the session always sets itself to the name specified towards the end of the code, even if that thumbnail was never clicked
     
    roisinD, Apr 13, 2007 IP
  4. IsRoss()

    IsRoss() Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That would be because CF is ignoring the 'onclick' and parsing the coldfusion code for each thumbnail. Instead of using the onclick method, you could have each thumbnail link to a coldfusion template that sets the session variable, and then redirects back to your main page. For example:

    <a href="set_the_variable.cfm?animal=leo"> {your image} </a>

    set_the_variable.cfm
    ---------------------
    <cflock scope="session" type="exclusive" timeout="30"><cfset session.animal = #url.animal#></cflock>
    <cflocation url="my_original_page.cfm" addtoken="no">
     
    IsRoss(), Apr 13, 2007 IP
  5. roisinD

    roisinD Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah thats perfect, thank you very much!
     
    roisinD, Apr 13, 2007 IP
  6. IsRoss()

    IsRoss() Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Glad to be of help!
     
    IsRoss(), Apr 13, 2007 IP
  7. datropics

    datropics Peon

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #7
    good job IsRoss() - glad you got your help roisinD
     
    datropics, Apr 13, 2007 IP
  8. IsRoss()

    IsRoss() Peon

    Messages:
    116
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    thanks datropics! Just trying to do my part, because someday I'll be the one askin'.
     
    IsRoss(), Apr 13, 2007 IP