Home All Groups Group Topic Archive Search About

Pass an array to javascript

Author
24 Mar 2005 2:43 PM
ruca
Hi,

How can I pass an array string to javascript?

I have this:

in ASP.NET VB code:

--------------------------------------------------------------------
        Dim siteName(100) As String
        Dim siteLink(100) As String
        Dim i As Integer

        siteName(0) = "New JavaScripts"
        siteName(1) = "Item 2"
        siteName(2) = "Item 3"
        siteName(3) = "Item 4"
        siteName(4) = "Item 5"
        siteName(5) = "Item 6"
        siteLink(0) = "link1"
        siteLink(1) = "link2"
        siteLink(2) = "link3"
        siteLink(3) = "link4"
        siteLink(4) = "link5"
        siteLink(5) = "link6"

        Dim sbScript As New System.Text.StringBuilder
        sbScript.Append("<script language='javascript'>")
        sbScript.Append(Environment.NewLine)
        sbScript.Append("createMenu('siteName','siteLink');")
        sbScript.Append(Environment.NewLine)
        sbScript.Append("</script>")
        RegisterStartupScript("OpenMenu", sbScript.ToString())
--------------------------------------------------------------------

in HTML code I have this (at javascript, of course):

function createMenu(siteName, siteLink)
{
for (i = 0; i <= siteName.length - 1; i++)
  document.write('<a href=' + siteLink[i] + '>' + siteName[i] + '</a><br>');
}

--------------------------------------------------------------------

What's wrong????


--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Author
24 Mar 2005 4:20 PM
Joseph Byrns
Where you have:

sbScript.Append("createMenu('siteName','siteLink');")

You could do:

sbScript.Append("createMenu(new
Array('Item1','Item2','Item3'),'siteLink');")
Author
28 Mar 2005 5:37 PM
ruca
Dont't work like that.
:(

Any more ideas, p l e a s e????


--
Programming ASP.NET with VB.NET
Thank's (if you try to help me)
Hope this help you (if I try to help you)
ruca

Show quoteHide quote
"Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> escreveu na mensagem
news:ekTEs1IMFHA.1472@TK2MSFTNGP14.phx.gbl...
> Where you have:
>
> sbScript.Append("createMenu('siteName','siteLink');")
>
> You could do:
>
> sbScript.Append("createMenu(new
> Array('Item1','Item2','Item3'),'siteLink');")
>
Author
28 Mar 2005 7:08 PM
Bruce Barker
a quick look at the docs would reveal  Page.RegisterArrayDeclaration which
has sample code.

-- bruce (sqlwork.com)


Show quoteHide quote
"ruca" <ru***@iol.pt> wrote in message
news:enKOO07MFHA.2748@TK2MSFTNGP09.phx.gbl...
> Dont't work like that.
> :(
>
> Any more ideas, p l e a s e????
>
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> escreveu na mensagem
> news:ekTEs1IMFHA.1472@TK2MSFTNGP14.phx.gbl...
>> Where you have:
>>
>> sbScript.Append("createMenu('siteName','siteLink');")
>>
>> You could do:
>>
>> sbScript.Append("createMenu(new
>> Array('Item1','Item2','Item3'),'siteLink');")
>>
>
>
Author
29 Mar 2005 8:20 AM
Joseph Byrns
That's strange, it works fine here. Hmmm.


Show quoteHide quote
"ruca" <ru***@iol.pt> wrote in message
news:enKOO07MFHA.2748@TK2MSFTNGP09.phx.gbl...
> Dont't work like that.
> :(
>
> Any more ideas, p l e a s e????
>
>
> --
> Programming ASP.NET with VB.NET
> Thank's (if you try to help me)
> Hope this help you (if I try to help you)
> ruca
>
> "Joseph Byrns" <josephby***@nnoossppaamm-yahoo.com> escreveu na mensagem
> news:ekTEs1IMFHA.1472@TK2MSFTNGP14.phx.gbl...
>> Where you have:
>>
>> sbScript.Append("createMenu('siteName','siteLink');")
>>
>> You could do:
>>
>> sbScript.Append("createMenu(new
>> Array('Item1','Item2','Item3'),'siteLink');")
>>
>
>