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

Java Script variable 1

Status
Not open for further replies.

Parasu

Technical User
Mar 11, 2001
38
0
0
PH
Hi all,
I want to pass a Java Script variable's value from Java Script to the ASP code. Is this possible.
Example,
<script language = &quot;java script&quot;>
{
var a;
a = 100;
}
<%
response.write (a)
%>

Is this possible. Can I use the java sript variable from within an ASP code.

Very urgent
Kindly help
Thanx in advance
Parasuraman Parasuraman
 
Hi parasu,

Alas, no.

You have to keep in mind that ASP is a Server script, while JavaScript is Client side. For ASP (meaning IIS) to recognize the variable a it has to pass through the server.

You can accomplish this by reloading the same page with the value of a added as a querystring and then display it like this:

<%=Request.QueryString(&quot;a&quot;)%>
(Should check if it exists)

But, in your example, this isn't needed, just write:

document.write(a) and let JavaScript do the writing.

Hope I could help you a bit? :p

Kristof
 
Dear Kristof,
Thanx for that. But, will the QueryString will pass even the java script variable??
Kindly help me by showing some sample code
Thanx again Parasuraman
 
Well, here goes:

This is the code for a page which I called jsasptest.asp.

<html>
<head>
<title>ASP Test</title>
<script language=&quot;JavaScript&quot;>
var a;
a = 100;

function reloadPage(val) {
url = &quot;jsasptest.asp?a=&quot; + val
window.location.href = url;
}
</script>
</head>

<BODY BGCOLOR=&quot;#FFFFFF&quot;>
<%if not VarType(Request.QueryString(&quot;a&quot;)) = 0 then%>
<%=Request.QueryString(&quot;a&quot;)%>
<%else%>
<a href=&quot;javascript:reloadPage(a)&quot;>Reload</a>
<%end if%>
</body>
</html>

You could also relocate to another page and let that one do the output.
(Ofcourse, this is a simplied example)

Glad to be of service.
 
Thanx alot Kristof
So nice of u. Parasuraman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top