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

Help:How to pass client side javascript variables to asp 1

Status
Not open for further replies.

bugeditor

Technical User
Oct 9, 2001
44
IN
Hi,
Can anybody please help me with snippet..Just..Howto pass client side javascript variables to asp session variables..

Say I have following
<script language=javascript>

Myfunc(){
var myvar1 = x;
var myvar2 = y;

// I want them here to be trapped into session variables
//above say myvar1 into session(&quot;myvar1&quot;) and myvar2 into session(&quot;myvar2&quot;)


}

</script>
Is it possible..If so can anybody

regards
 
It is not possible to call directly an asp varable from client side script.
But u may use a submit form to initialize the asp variables.
Or u could use Remote Scripting Object. ________
George, M
 
One way would be to pass the variables to a new window running an asp script to store.

Example.

MainPage.htm contains the following:
<script>
function SetVars(strName, intAge){
myVar1 = strName;
myVar2 = intAge;
URL = &quot;StoreVars.asp?Var1=&quot;+myVar1+&quot;&Var2=&quot;+myVar2;
window.open(URL,&quot;&quot;,&quot;height=10,width=10,top=10,left=10&quot;);
}
</script>

StoreVars.asp contains the following:
<%
Session(&quot;UserName&quot;)=Request(&quot;Var1&quot;)
Session(&quot;UserAge&quot;)=Request(&quot;Var2&quot;)
%>
<script>self.close();</script>

This is one way, it's an alternative to reloading the current window. You could pop a relevant message in the StoreVars window - it's only visible for a moment.

Martin.
 
This should do it

The Client side

<script language=javascript>
Myfunc(){
var myvar1 = x;
var myvar2 = y;
location.href='}
</script>

The Server Side

<%
Response.Status = &quot;204&quot;
Session(&quot;myvar1&quot;) = Request(&quot;myvar1&quot;)
Session(&quot;myvar2&quot;) = Request(&quot;myvar2&quot;)
%>

Steve
 
Thanks Martin. That was very informative, especially the suggestion to use a new window with some unimportant message like &quot;Please Wait&quot;.

Good Thinking..

ToddWW
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top