View Full Version : Passing an Array from ASP to Javascript

04-09-2003, 08:23 PM

I was wondering if anyone has any ideas on how to pass an array from ASP to Javascript? I don't think that this can be done by storing the ASP's contents into a hidden input field.

Any help would be welcome!

Thanks! :thumbsup:

04-09-2003, 08:29 PM
I don't know anything about ASP, but I think it's a common thing between server side languages that they make the content of the web page, right?! So, it means you can write anything into the page and actually you make the page, so, instead of writing HTML into your page, you can also write Javascript.



I assume that Write is a valid code in ASP for writing things into the page. I said I don't know ASP! :o

04-10-2003, 10:21 AM
Yeah, pretty well - just to add my 2p-worth :)

I don't think there's any way of passing the array as an object between them; as ConfusedOfLife says, you gotta write it out yourself. So...

Dim myASPArray
myASPArray=Array("john","paul","george", "ringo")

response.write("<script language=""JavaScript"">" & vbCrLf)
response.write("var myJSArray=new Array()" & vbCrLf)

for c=lBound(myASPArray) to uBound(myASPArray)

any help?

04-10-2003, 10:23 PM
There is definitely NO way! These 2 languages work in 2 different levels. When everything is finished with ASP/PHP, then VBScript/Javascript starts to work. There is no connection, unless you generate the client side code by the server side language.

I can remember a good example now, it's about a site that uses PHP to retrieve information/pictures from the database and then populate the javascript arrays with them (by creating the arrays server side) and then finishing the PHP. The writer claimed that it reduced the download time from somehow 20 secs to only 3 or 4 secs! Here it's the address: