954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to pass a array from asp to javascript

how to pass a array from asp to javascript

Deepa
Newbie Poster
19 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 
how to pass a array from asp to javascript

You might want to use the join method in Jscript to populate your client side javascript. Use the join like this on an array called cars:

<%
     var sep = "','";
     var carlist = cars.join(sep);
%>


Note: Make sure that you include the appropriate quotes in the sep string. Its very difficult to illustrate here but you need a doublequote then singlequote then a comma then a single quote and then a double quote (with no spaces in between): "','" ;)

Then take the list that was created and populate your clientside script. I will create the clientside javascript array called fooCars:

<script language="JavaScript">
     fooCars = new Array('<%=carlist%>');
</script>


Again make sure that you surround your variable call in ASP by single quotes.

This should do it.

Javaknight
Newbie Poster
10 posts since Dec 2004
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You