You could also use javascript to write a cookie then as Bull said reload the page and set the session variable based on the cookie. (if it must be a session variable)
Of course this would make you dependent on cookies being enabled. Not necessarily a good thing.
Wow JT that almost looked like you knew what you were doing!
pixl8r: Of course if cookies weren't enabled, session variables wouldn't be working either, so that would make the whole thing moot
An extension and agreement with the No's above:
Session variables are stored on the server. Javascript executes on the client. Remember that the HTTP protocol passes requests to the server for documents and then documents back to the user. Cookies are actually kind of a hack (they are passed in the headers of the documents and requests). So there is no other communication between the client and server. Client-side script has no access to the server and only limited access on the client, although you could use a hidden iframe or popup window to send a request for a page with the variable in te querystring, then close it after it has been passed back. Tis would have the same effect as posting back to the server but wouldn't be a visible to the user.
Sessions are assigned unique ids per user, so you need to have the user keep track of their session id somehow. You could do this with a form variable or a cookie. Else you can't tell what data is associated with what user.
You could make good use of form variables to keep from having to have cookie or session variables on your web application or you could just make a comment on your website about enabling first party cookies.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.