how to pass a array from asp to javascript

Member Avatar for Javaknight

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.