Go Back   AnandTech Forums > Software > Software for Windows

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Home and Garden
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 04-30-2003, 08:15 PM   #1
Gow
Member
 
Join Date: Aug 2000
Posts: 35
Default reading session variables in javascript??

Hi there

What i need is a site or some code that will allow me to read the contents of a session variable created in ASP...

The thing is i want to read it using javascript, can someone help, please

i have a 2d array created in ASP and stored in a session variable...

I want to check the contents of the array against multiple form text boxes, and i need it done in javascript..

can this be done?
am i trying to do the imposible?

i have searched for hours and not found an answer...

All help greatfully accepted

Thanks


Gow is offline   Reply With Quote
Old 04-30-2003, 08:31 PM   #2
Argo
Lifer
 
Argo's Avatar
 
Join Date: Apr 2000
Posts: 10,014
Default reading session variables in javascript??

There is no direct way. Session persists on the server, javascript runs on the client. Depending on what your goal is, the only workaround would be to have asp page write out different JSP based on what the value of the session variable is.

You can also write a thread or asp page that will listen on a specific port and serve request for the jsp script running on the client. This solution is pretty cumbersome though.
Argo is offline   Reply With Quote
Old 04-30-2003, 09:49 PM   #3
GilletteCat
Member
 
Join Date: Dec 2001
Posts: 181
Default reading session variables in javascript??

let's say you have a one-dimentional VB-safe array and you have assigned it to a session variable on one page to be able to retrieve it on another.
the code for the <head> of the retrieving page would be:
<script language=javascript>
var MyVBArray = new VBArray(<%=Session("MySessionArray_Blah_Blah")%>);
var MyJSArray = MyVBArray.toArray();
</script>
If you want to compare the value of a text-box object on the page to a value in the array, you have to know which index in the array that value occupies. For example, we would compare the value of the text-box my_input_field_1 to the value of the first member of the array:
<script language=javascript>
if(document.myform.my_input_field_1.value == MyJSArray[0]) {
.....
}
Remember, the array index is 0-based.

Hope it helps.
__________________
"I've never gotten anyone pregnant when there are occasions where it has been questionable 'why' I didn't. I've smoked a lot of pot in my day and I'm beginning to think I messed my boys up..." - Samus
"Unbelievable find, you get my girlfriend for a week!" - fordLorider
GilletteCat is offline   Reply With Quote
Old 04-30-2003, 09:56 PM   #4
Argo
Lifer
 
Argo's Avatar
 
Join Date: Apr 2000
Posts: 10,014
Default reading session variables in javascript??

GilletteCat:

I had no idea there was a way to do that. I was thinking from JSP/Servlets perspective.
Argo is offline   Reply With Quote
Old 04-30-2003, 10:23 PM   #5
GilletteCat
Member
 
Join Date: Dec 2001
Posts: 181
Default RE: reading session variables in javascript??

yeh, it's rather plain
but, i guess, you have to have faced it once before to know it.
__________________
"I've never gotten anyone pregnant when there are occasions where it has been questionable 'why' I didn't. I've smoked a lot of pot in my day and I'm beginning to think I messed my boys up..." - Samus
"Unbelievable find, you get my girlfriend for a week!" - fordLorider
GilletteCat is offline   Reply With Quote
Old 04-30-2003, 11:51 PM   #6
eklass
Golden Member
 
Join Date: Mar 2001
Location: Chicago!
Posts: 1,218
Default reading session variables in javascript??

you will have to read the session variable sfrom ASP and have them print out the javasript code to check for it

in otherwords, use serverside code to create dynamic client-side code

i do this when checking out in an ecommerce storre and the user wants t0o specify "same as billing" for thier shipping address. when the user clicks the checkbox, all the text boxes are fille din via javascript. the way javascipt know is i use php to print out:

document.form[0].s_name.value = 'john doe';


wherein the john dow part between the single quotes is a session vairable

if you don't get it, read my sig. if you still dont' get it, maybe it's just over your head (the process, not the pancakes)
eklass is offline   Reply With Quote
Old 05-01-2003, 04:56 AM   #7
Gow
Member
 
Join Date: Aug 2000
Posts: 35
Default reading session variables in javascript??

This does not work for me.....



Quote:
<script language=javascript>
var MyVBArray = new VBArray(<%=Session("MySessionArray_Blah_Blah")%>);
var MyJSArray = MyVBArray.toArray();
</script>
I don't know why, it just dont...

I got this error mesage once..

Response object, ASP 0106 (0x80020005)
An unhandled data type was encountered.


can anyone tell me how to read a normal session variable......

is it somthing like

var test = <%sesstion("test")%>;

if i can get that to work i may be able to sort the rest out...
Gow is offline   Reply With Quote
Old 05-01-2003, 06:23 PM   #8
eklass
Golden Member
 
Join Date: Mar 2001
Location: Chicago!
Posts: 1,218
Default reading session variables in javascript??

this is what you need:


<script>
var something = '<%=Session("something_else")%>';
</script>
eklass is offline   Reply With Quote
Reply

Thread Tools

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 On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 01:23 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.