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:
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...
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
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">