How can I pass ASP variables to javascript variables
(in the same page)?
Thanx in advance.
Tim
Printable View
How can I pass ASP variables to javascript variables
(in the same page)?
Thanx in advance.
Tim
Here is an example which puts the value of a VBScript variable into a JavaScript
alert box:
Response.Write "<script language='JavaScript'>alert('The value is " & MyVBScriptVariable
& "');</script>"
Best regards,
-Paul
J. Paul Schmidt, MBA
Databases on the Web
http://www.Bullschmidt.com
Hi Tim,
Here is a simple way to use a variable declared in ASP in JavaScript:
<%
Dim varASP 'a variable in asp
varASP = "Some value"
%>
<SCRIPT LANGUAGE="JavaScript">
<!--
function ShowValue() {
window.alert('<% = varASP %>')
}
-->
</SCRIPT>
Just make sure that the asp variable is declared and initialized before being
used in the JavaScript part.
Hope this one helps !
Dylan.
"Tim" <sam213@cdg.com> wrote:
>
>How can I pass ASP variables to javascript variables
>(in the same page)?
>
>Thanx in advance.
>Tim
Yes,
All above methods work fine, but I still believe in:
<SCRIPT Language="JavaScript">
varName = "<%=strName%>"
...
...
</SCRIPT>
This actually 'copies' the variable to client side that can be 'used' anywhere
in client side
Cheers
Rohit