473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Pass an array to javascript

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
Nov 19 '05 #1
6 5556
dgk
On Thu, 24 Mar 2005 14:43:29 -0000, "ruca" <ru***@iol.pt> wrote:
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????


I'm just learning this stuff but I'll take a shot. The VB code is
executing on the server and the javascript on the browser. You would
need to pass the information back through something they both have in
common. Perhaps the Document object?
Nov 19 '05 #2
Where you have:

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

You could do:

sbScript.Append("createMenu(new
Array('Item1','Item2','Item3'),'siteLink');")
Nov 19 '05 #3
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" <jo*********@nnoossppaamm-yahoo.com> escreveu na mensagem
news:ek**************@TK2MSFTNGP14.phx.gbl...
Where you have:

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

You could do:

sbScript.Append("createMenu(new
Array('Item1','Item2','Item3'),'siteLink');")

Nov 19 '05 #4
Hello ruca,

Look at Page.RegisterArrayDeclaration...

--
Matt Berther
http://www.mattberther.com
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????


Nov 19 '05 #5
a quick look at the docs would reveal Page.RegisterArrayDeclaration which
has sample code.

-- bruce (sqlwork.com)
"ruca" <ru***@iol.pt> wrote in message
news:en**************@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" <jo*********@nnoossppaamm-yahoo.com> escreveu na mensagem
news:ek**************@TK2MSFTNGP14.phx.gbl...
Where you have:

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

You could do:

sbScript.Append("createMenu(new
Array('Item1','Item2','Item3'),'siteLink');")


Nov 19 '05 #6
That's strange, it works fine here. Hmmm.
"ruca" <ru***@iol.pt> wrote in message
news:en**************@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" <jo*********@nnoossppaamm-yahoo.com> escreveu na mensagem
news:ek**************@TK2MSFTNGP14.phx.gbl...
Where you have:

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

You could do:

sbScript.Append("createMenu(new
Array('Item1','Item2','Item3'),'siteLink');")


Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Miguel | last post by:
Hello. I have a Javascript function that validates an specific form. As parameters this function receives an array of elements to be checked. Depending on the form in cause, the array could have...
0
by: Matt | last post by:
My problem is to allow ASP to interact with JSP, and I pass JavaScript object in my approach, but I wonder if it will work in network, not just in local machine. For testing purposes, the...
3
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
5
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code ("f" is my form object) : var btnChosen; for...
4
by: Sunny | last post by:
Hi, I am at present working on a jsp page which has a single text field. Upon entering a value in the field, i am trigerring an onChangeEvent() which calls a method of javascript. I am also...
2
by: Augusto Cesar | last post by:
Hello people. How can I Pass ASP Array variable to Javascript; I´m to trying this: <script language="JavaScript"> var x = new Array(10);
2
by: André | last post by:
Hi, I have to pass a lot of variables from vb.net to javascript using client callback. the problem is that there are single variables, but also arrays with differents indexes. I have two...
1
by: thomas_okken | last post by:
I'm working on a little C# DLL that will let me capture audio from within Internet Explorer. The idea is that the C# object, once it is recording, will periodically invoke a JavaScript callback,...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
1
by: mchen1117 | last post by:
I try to display a random image alone with text and link, I find this javascript and did some edit as needed, I don't know how I can pass document.write() value to HREF's URL, Please help ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.