Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2003
    Location
    Ottawa, Ontario, Canada
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing an Array from ASP to Javascript

    Hi!

    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!
    Jason Beaudoin
    Web Designer
    Canadian Army

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Pseudocode:
    Code:
    Write("<script>myArray=['1','2','3'];</script>");
    I assume that Write is a valid code in ASP for writing things into the page. I said I don't know ASP!
    Last edited by ConfusedOfLife; 04-09-2003 at 09:33 PM.

  • #3
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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)
    response.write("myJSArray["&c&"]="""&myASPArray(c)&""";"&vbCrLf)
    next
    response.write("</script>")
    %>


    any help?

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    www.skyscraperpage.com


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •