Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why do I get an undefined when passing an Array?

Status
Not open for further replies.

sgmurphy

Programmer
Jul 25, 2007
4
US
Basically I fill an ArrayList in C# then Invoke a javascript where I pass this Array. The .Count ArrayList is passed accurately but when I try to read values in it, I get "undefined".

Anyone know why or what I need to do to be able to read the values?

C# code:
void PassData_BtnClick(object sender, EventArgs e)
{
ArrayList SelectDisplay = new ArrayList();
SelectDisplay.Add("Start");
SelectDisplay.Add("One Test");
SelectDisplay.Add("Two Test");
SelectDisplay.Add("Three Test");

browser.Document.InvokeScript("DisplayArrayValue", new object[] { SelectDisplay});
}

html & javascript:
<html>
<body>

<script language="javascript" type="text/javascript">

function DisplayArrayValue(sDisplay)
{
alert("sDisplay[3] = " + sDisplay[3]);
}

</script>
</body>
</html>

Thanks!
Sean Murphy
 
Seems to me that you could pass SelectDisplay directly in the InvokeScript method.

This is a guess, but it seems valid based on other examples I looked at.

Code:
browser.Document.InvokeScript("DisplayArrayValue", [!]SelectDisplay[/!]);


[monkey][snake] <.
 
I get sDisplay = " for the following. So nothing.

function DisplayArrayValue(sDisplay)
{
alert("sDisplay = " + sDisplay);
}
 
Then if monksnake's solution fails, I'd take this to a .Net forum to ask how to correctly pass arrays into JS. If it's not being passed in, then there's not much we can do to debug the client-side.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top