JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 7th, 2010, 09:49 PM
gurkus gurkus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2010
Posts: 5 gurkus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 46 sec
Reputation Power: 0
Javascript newbie question

Figured out my first issue, so just edited this since there were no responses. So im trying to pass info from a php array to a javascript array, from what ive read this is the general idea but it doesnt work, what am i missing.

Code:
  var map;
  <?php
  $listofips = array( 
				array(40.730885, 73.99738 , "Number 1"),
               	array(50.730885, 73.99738 , "Number 2"),
               	array(60.730885, 73.99738 , "Number 3") 
             ); 
  ?>
  
  var _iplist = new Array();
  
  for (x = 0; x<=3;x++)
  {
	  
	  var text = "Number " + x;
	  var _ip = new Array(<?php echo $listofips[x][0] ?>,<?php echo $listofips[x][1] ?>,<?php echo $listofips[x][2] ?>);
	  //var _ip = new Array(40.730885+x*10,-73.99738+x*10,text);
	  _iplist.push(_ip);
  }

Reply With Quote
  #2  
Old April 8th, 2010, 03:29 AM
gurkus gurkus is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2010
Posts: 5 gurkus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 46 sec
Reputation Power: 0
I feel like im getting closer, still no good though

Code:
  <?php
  
  $listofips = array( 
				array(40.730885, 73.99738 , "Number 1"),
               	array(50.730885, 73.99738 , "Number 2"),
               	array(60.730885, 73.99738 , "Number 3") 
             ); 
  
  for ($x = 0; $x<count($listofips); $x++)
  { 
	  echo "var _ip = new Array(" . $listofips[x][0] . "," . $listofips[x][1] . "," . $listofips[x][2] . ");" . "\n"; 
	  echo "_iplist.push(_ip);" .  "\n";
  }
  ?>

Reply With Quote
  #3  
Old April 12th, 2010, 02:38 AM
Thinias Thinias is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2010
Posts: 78 Thinias User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 h 58 m 48 sec
Reputation Power: 9
Have you tried echoing a javascript header around the array declaration? I'm not an expert, but a php echo is going to echo raw html, as I understand it.

Code:
  <?php
  
  $listofips = array( 
				array(40.730885, 73.99738 , "Number 1"),
               	array(50.730885, 73.99738 , "Number 2"),
               	array(60.730885, 73.99738 , "Number 3") 
             ); 
  
echo "<script type=\"text/javascript\">";
  for ($x = 0; $x<count($listofips); $x++)
  { 
	  echo "var _ip = new Array(" . $listofips[x][0] . "," . $listofips[x][1] . "," . $listofips[x][2] . ");" . "\n"; 
	  echo "_iplist.push(_ip);" .  "\n";
  }
echo "</script";
  ?>

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Javascript newbie question


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap