Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: setting session variables in javascript


Message #1 by "Bryan Lott" <bryan.lott@a...> on Thu, 24 Jan 2002 17:14:56
Please understand the fundamental principles of what you're doing:

ASP code (enclosed in <%%>) is executed first on the server.  This generates
a stream of HTML which is sent to the browser on the client machine.  Once
the page is loaded in the client, thats when client-side code, usually
javascript, can then be executed on the client, normally in response to user
actions.

Session variables exist on the server, and cannot be modified from the
client.  You need to submit a form back to the server, then in the ASP which
processes the form you can set session and application variables.

The reason that javascript stops working with your code is that all the
browser receives is 

= "test";

which is not a valid statement.  If the session variable already had a value
in it, then the browser would receive

someval = "test"

in which case it would treat "someval" as the name of a variable - also
nonsense.

I appologise if my initial statement came across as cheeky, but I've seen
questions like this come up time and time again on these lists.

(There are other technologies such as remote scripting and xmlhttp which
would allow you to execute server code without having to leave the page in
the browser, but I'll not go into that just now...)


-----Original Message-----
From: Bryan Lott [mailto:bryan.lott@a...]
Sent: 24 January 2002 17:15
To: JavaScript HowTo
Subject: [javascript_howto] setting session variables in javascript


I would very much like to set a session variable in a Javscript funtion. I 
have tried many things but with no luck. The following doesn't give me an 
error, however it stops the javascript from functioning.

This is what I have tried resently.

<%=session("CellNumber")%> = "test";

thanks
$subst('Email.Unsub').

________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com

Headquarters Address & Contact Numbers

150 Broomielaw
5 Atlantic Quay
Glasgow
G2 8LU.
Tel:  +44 (0) 141 248 2700.
Fax:  +44 (0)141 221 3217

 This message is sent in confidence for the addressee only.
It may contain legally privileged information. The contents are not to
be disclosed to anyone other than the addressee. Unauthorised recipients
are requested to preserve this confidentiality and to advise the sender
immediately of any error in transmission.



  Return to Index