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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Acessing server side variables from client side script

Status
Not open for further replies.

arprog

Programmer
Sep 6, 2001
2
US
I have 2 simple asp pages here, where i want to get a server side variable from a client side vbscript. The following code works well and i am able to get the server side variable and display it in the client side message box. Notice that the client side script is inside the <body> tag.
***********************************************
<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
</HEAD>
<BODY>
<% dim testvariable
testvariable = &quot;Hello&quot;
%>
<form name=form1 >
<input type=button name=&quot;button1&quot; value=&quot;Click Me&quot;>
</form>
<P> </P>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=vbscript>
<!--
sub button1_onclick()
msgbox &quot;<%=testvariable%>&quot;
end sub
//-->
</SCRIPT>
</BODY>
</HTML>
********************************************************
Now in the following page the i am not able to get the value of the server side variable. In this case i move the client side vbscript in the <head>section on the page instead of the body

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<SCRIPT ID=clientEventHandlersJS LANGUAGE=vbscript>
<!--
sub button1_onclick()
msgbox &quot;<%=testvariable%>&quot;
end sub
//-->
</SCRIPT>
</HEAD>
<BODY>
<% dim testvariable
testvariable = &quot;Hello&quot;
%>
<form name=form1 >
<input type=button name=&quot;button1&quot; value=&quot;Click Me&quot;>
</form>
<P> </P>
</BODY>
</HTML>
********************************************************
What is the difference? why does it work when the script is in the body tag. also it does not work even if i put the client side vbscript above the server side code in the Body tag itself. Does it not always execute server side script first?
Any responses will be appreciated.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top