Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session <SCRIPT>

Status
Not open for further replies.

NevG

Programmer
Oct 10, 2000
162
GB
Hi gang

Can somebody please tel me how I can change the contents of a Session variable inside the <SCRIPT></SCRIPT> tags.

I can do it inside the <% %> tags but I want to be able to do so in the other tags.

I have tried Session(&quot;Variable&quot;) = &quot;&quot; but no luck . Please help

Nev
 
A Session variable is a server side variable. You cannot directly change it from the client side.

What you can do is assign the value to a client side variable:
Code:
<script>
var thisvar = <%= Session(&quot;Variable&quot;) %>
...
</script>

Now, you can manipulate
Code:
thisvar
. If you need the new value replaced in the original Session variable, then just pass it back to the next server side script using a hidden field or a querystring.
Code:
Session(&quot;Variable&quot;) = Request.QueryString(&quot;thisvar&quot;)

HTH

Choo Khor
choo.khor@intelebill.com
 
Dear Nev,

If you are trying to use server side script tags...

<script language=javascript runat=server>
function setMySessionVar( strVal){
Session(&quot;MyVar&quot;) = strVal;
}
</script>

Note the use of the function. Server code inside of <script> tags does not execute inline, that's what the <%%> tags do. So you must declare functions and call them to execute the code. So you still need to do this somewhere in the page

<%
setMySessionVar(&quot;Hello world&quot;)
... more code etc
%>

Hope this helps
-pete
 
From the client side in JavaScript you have to submit a form that executes the server side session variable changes.
I just did this in an intranet application. I had two frames. From the top frame the user selected some options and that, on the client side, generated the submission of a from IN THE OTHER FRAME which reset the session variables. The user still retained control in the upper frame!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top