how to pass a array from asp to javascript

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2004
Posts: 19
Reputation: Deepa is an unknown quantity at this point 
Solved Threads: 0
Deepa Deepa is offline Offline
Newbie Poster

how to pass a array from asp to javascript

 
0
  #1
Nov 29th, 2004
how to pass a array from asp to javascript
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 10
Reputation: Javaknight is an unknown quantity at this point 
Solved Threads: 1
Javaknight's Avatar
Javaknight Javaknight is offline Offline
Newbie Poster

Re: how to pass a array from asp to javascript

 
0
  #2
Jan 5th, 2005
Originally Posted by Deepa
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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <%
  2. var sep = "','";
  3. var carlist = cars.join(sep);
  4. %>

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:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="JavaScript">
  2. fooCars = new Array('<%=carlist%>');
  3. </script>

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

This should do it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC