Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing session variables
Message
General information
Forum:
Internet
Category:
Javascript
Miscellaneous
Thread ID:
01289093
Message ID:
01289461
Views:
12
This message has been marked as the solution to the initial question of the thread.
You can't access < %= % > expressions in a separate file since the separate javascript file is not an ASPX/ASP page hence it doesn't evaluate that value.

There are a few ways around this.

One is you can set a global variable in your main ASPX/ASP file :

< script type="text/javascript>
var sessionVar = "< %= Session["mySessionVar"] % >";
< /script>

Put that on the bottom before the form tag of your main form and then in the .js file you should be able to reference sessionVar as a global variable.

+++ Rick ---


>I have all my Javascript in a separate file linked to an html page. I am trying to get the session variable value from within a Javascript function. If the function code is on the html page it works, but it won't work in the linked file. I have written the value to the page with VBScript. I use a hidden text to pass to the Session variable. The Session variable has the correct value. Anyone know why I cannot get the Session variable value when the js code is in a linked file?
>Code sample below:
>
>// fills comboxbox for vendors
>function SelectVendor(classid) {
>	var selCls = < %=Session("nSelCls")% >;
>	if (selCls != 0){
>		startForm.cboClasses.selectedIndex = selCls;
>		classid=selCls;
>	}
>	var vendors=xmlClasses.childNodes(0).childNodes(classid);
>	startForm.cboVendor.options.length=0;
>	for (i=0;i<vendors.childNodes.length;i++) {
>		oOption=document.createElement("OPTION");
>		o=vendors.childNodes(i);
>		new_option=o.getAttribute("vendor_name");
>		oOption.text=new_option;
>		oOption.value=new_option;
>		startForm.cboVendor.options.add(oOption);
>	}
>	SelectPayType(classid,0);
>}	
>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform