Click to See Complete Forum and Search --> : PASSING ASP VARIABLES TO JAVA SCRIPT
lab
Aug 16th, 2000, 07:50 AM
I'm new to ASP and need some help.
I've got an asp page that does some validation and then
I pass a variable to a Client Side Java Script function.
The JS function does not recognize the ASP variable.
I tried using "document.all['<%=ASPVariableName%>'].value"
with no success.
The only way I found to pass anything to the JS function
is to create a hidden field on the form and reference it
like "form.HiddenFieldName.value"
Any suggestions would be greatly appreciated.
S@NSIS
Aug 16th, 2000, 08:08 AM
Hi,
Without seeing your code, it's hard to work out where you want the variable names to go.
If you just want to put the ASP variable into a JS variable then try
MyVar = <% Request.QueryString("ASPvariable") %>
or if you are using it to reference a field in a form:
document.all.form1.<%Request.QueryString("ASPvariable")%>.value
Again, without your code I really don't know what you are trying to do but I hope this helps!
Shaun
S@NSIS
Aug 16th, 2000, 08:10 AM
oops...should be <% Response.Write Request.QueryString("ASPvariable") %>
asabi
Aug 17th, 2000, 03:00 AM
is there any place to see more of the code ?
After the page is loaded, right click on the browser, and click the "view source" see if there is anything in the JavaScript that is wrong (like the variable value missing or something).
try putting a
response.write (request ("variable")) at the begining of the page, and see if you can see the value.
The JavaScript / HTML don't even know it is an ASP page, so there is no diffrence if you use the ASP in JavaScript or in HTML, the ASP is being proccessed before the page is loaded (Server side).
dvst8
Aug 17th, 2000, 01:28 PM
yeah, if you need values from ASP, just define them outside your JS function, assign them values using simple ASP statement, and then pass them into your JS function.
dvst8
dvst8
Aug 17th, 2000, 01:30 PM
asabi is absolutely right.
the ASP is processed way before any client-side JS gets processed.
that's why JS and ASP don't work togehter.
dvst8
S@NSIS
Aug 17th, 2000, 01:38 PM
Hi,
We have solved the problem now! but thnx anyway. The way (and the only way I believe) to pass the ASP variable to the Javascript variable was top put this in the ASP page:
dim aBaseURL
BaseURL="Http://VB-world.net"
Response.Write("<Script>")
Response.Write("var jBaseURL='" & aBaseURL & "'")
Response.Write("</Script>")
which then showed up on the HTML page as:
<Script>
var jBaseURL='Http://VB-world.net'
</Script>
He could then access this Javascript variable as he would any other.
There was more stuff to it as well but that is how I did that bit!!! ;)
Cheers,
Shaun
lab
Aug 17th, 2000, 03:17 PM
Thanks Shaun. It worked just fine.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.