Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 7th, 2005, 08:16 AM
Registered User
 
Join Date: Sep 2005
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old September 7th, 2005, 09:08 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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

Reply With Quote
  #3 (permalink)  
Old September 7th, 2005, 09:40 AM
Registered User
 
Join Date: Sep 2005
Location: , , .
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
Reply With Quote
  #4 (permalink)  
Old September 7th, 2005, 10:00 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
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]

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:24 AM.


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