-
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.
-
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
Code:
MyVar = <% Request.QueryString("ASPvariable") %>
or if you are using it to reference a field in a form:
Code:
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
-
oops...should be <% Response.Write Request.QueryString("ASPvariable") %>
-
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).
-
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
-
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
-
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:
Code:
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:
Code:
<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
-
Thanks Shaun. It worked just fine.