CFSET and Onclick()

Perago
Perago used Ask the Experts™
on
Hey Experts,

I just have a quick question with CFSET and the Onclick() function.  I am trying to setup the text in a TH cell to be able to sort and then refresh the page afterwards..  I have setup a session variable called TaskSort which sets the ordering and it is defaulted upon login. Using the following code I can't get it to work.  I know my syntax is off but I can't seem to find any other resources to point me in the right direction.  Thanks in advanced for any help you can provide.


<th><a href="main.cfm" onclick="<cfset session.TaskSort = "TaskDueDate">">Due Date</a></th> 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
If you view-source on your browser, you will see that your onClick value is empty.. it will show    onClick=""

That's because Coldfusion is server side only, by the time the page is drawn, all Coldfusion is gone.  

I suggest simply changing your href to include a sort parameter.    href="main.cfm?sort=dueDate"    

It's more efficient that session variables for this and you can bookmark it.   If a user has more than one window open the sort order can change between that because sessions are shared.
I'm guessing you don't want to refresh the page, so you need to write a function to handle the click event and it will have to make an ajax call back to the server, to set your session variable.

Author

Commented:
Thanks Guys, I created a separate function as recommended to change the session sort variables.
why the "B" grade ?    You should only give a B if you didn't get what you needed...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial