Is't posibble to share session variable within asp and javascript code?
Session Variable
Collapse
X
-
It is possible to write a session variable to a javascript function by embedding it inside the function using server tags like this:
You can only set a session variable on the server so it must be passed from your javascript to the server through a form or the querystring.Code:<script type="text/javascript"> function test() { var a = '<%=Session("MySessionVar")%>'; alert(a); } </script>
Out of interest, why are you trying to do this?
Hope this helps,
Dr B -
No my code is setting a javascript variable to the value of a session variable as defined in your vbscript. Try using the following example and you'll see that the value of the javascript variable 'a' is set to the value of the session variable 'MySessionVar'.
Does this make sense?Code:<% Session("MySessionVar") = "Hello World!" %> <script type="text/javascript"> function test() { var a = '<%=Session("MySessionVar")%>'; alert(a); } </script> <body onload="test()"> </body>
Dr BComment
-
banu2001,
Why have you posted this? It looks like ASP.NET C# while this is the Classic ASP Forum and it also looks totally unrelated to the thread.
Dr BComment
-
Thanks DrBunchman :)Originally posted by DrBunchmanIt is possible to write a session variable to a javascript function by embedding it inside the function using server tags like this:
You can only set a session variable on the server so it must be passed from your javascript to the server through a form or the querystring.Code:<script type="text/javascript"> function test() { var a = '<%=Session("MySessionVar")%>'; alert(a); } </script>
Out of interest, why are you trying to do this?
Hope this helps,
Dr B
I never thought about doing this and I don't know why.
-FrinnyComment
Comment