Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 7th, 2005, 08:16 AM
Registered User
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Global Variables and ClientSide Javascript

Good Morning all,

(An ASP Beginners question):
Recently I learned about "application" and "session" variables defined in global.asa and now want to examine/use/update them from the client-side using javascript.

Following the examples in the Active Server Pages 3.0 book (Chap 8), I can at least show the value of the variables using vbscript **<%= Session("VisitorID")%>**, but so far have been unable to read them into a java defined variable, let alone change them! There must be away I am sure!

So in short.
 . I want to examine a variable created in the global.asa file
 . Change it (if necessary)
 . All from Java (client-Side).

Would some kind soul put me out of my misery - It's really doing my head in :(!

Kind Regards,
Michael

Michael
 
Old September 7th, 2005, 09:08 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Michael,

Because application and session variables are server-side and your JavaScript runs client-side, you cannot directly access the variables from JavaScript.

You could populate javascript variables with the values from the server when you build your pages e.g.
Code:
var myVar = "<%=Session("mySessionVar")%>";
Another way would be to write the server-side variable values into form fields and then access them from there.

If you want to update the variables from client-side, you will have to collect the details of the update on the client and then send them back to the server to make the changes.

HTH,

Chris

 
Old September 7th, 2005, 09:40 AM
Registered User
 
Join Date: Sep 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Chris for the speedy reply,

Although it is not the answer I wanted to hear! - Hardly your fault though :)

I really wanted to be able to adjust the session variables without reloading the page, (as the page in question calls another program that runs interactively).

If I could trouble you further...

Your initial suggestion: **var myVar="<%=Session("mySessionVar")%>";**
I build my pages using vbscript, so how do I include a java definition? (Yes, I really am a beginner!!)

As per the second suggestion, I guess I can hide an iframe with a hidden form in the page and have that refresh itself. I should be able to extract the session values from it and then modify them from my javascript then post the form back. Does that make sense? Are there security issues I should think about?

Thank you again,
Michael
 
Old September 7th, 2005, 10:00 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hey Michael,

Just to clarify, I was talking JavaScript and not Java.

If you want to write the values to JavaScript variables, just add the script to your html, something like...
Code:
<script language="JavaScript">
var myVar="<%=Session("mySessionVar")%>";
</script>
This will write the value into the script block before the page is sent to the browser.

Your idea about a hidden form would work, depending on your target audience, you could also consider M$ XmlHttp or Mozilla XMLHttpRequest objects, which allow a remote request direct from a script.

Cheers,

Chris
[/code]






Similar Threads
Thread Thread Starter Forum Replies Last Post
Pulling ServerSide Variables Into ClientSide Code kwilliams ASP.NET 2.0 Professional 3 February 6th, 2008 04:57 PM
capturing asp data in clientside javascript Terry Joseph Migliorino Javascript How-To 9 November 2nd, 2005 09:10 AM
capturing asp data in clientside javascript Terry Joseph Migliorino Javascript 1 October 31st, 2005 01:42 PM
Global variables zarol Beginning PHP 3 May 10th, 2005 06:17 AM
Global variables ps124 ASP.NET 1.0 and 1.1 Basics 6 April 6th, 2004 02:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.