Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.
Moderator: General Moderators
priyanka01
Forum Newbie
Posts: 1 Joined: Sun Nov 07, 2010 11:58 pm
Post
by priyanka01 » Mon Nov 08, 2010 12:05 am
Hi,
Code: Select all
path=new Array();
path[0]="<?= $field[0] ?>";
path[1]="<?= $field[1] ?>";
i want to insert it in loop for example
Code: Select all
path=new Array();
for (var i=0;i<path.length;i++){
path[i]="<?= $field[i] ?>"; // but its not working
}
but the above code is not working please tell me another way
Last edited by
Weirdan on Mon Nov 08, 2010 2:52 am, edited 1 time in total.
Reason: added syntax highlighting
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Mon Nov 08, 2010 3:16 am
You cannot do the second one because $field will only equal one value when you generate the Javascript. Either use the first method, or try generating JSON.
(#10850)
Jonah Bron
DevNet Master
Posts: 2764 Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California
Post
by Jonah Bron » Mon Nov 08, 2010 10:05 am
Or this (untested)
Code: Select all
var path = ["<?php echo implode('", "', $field); ?>"];
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Nov 08, 2010 10:16 am
Jonah Bron wrote: Or this (untested)
Code: Select all
var path = ["<?php echo implode('", "', $field); ?>"];
json_encode is almost always better:
Code: Select all
var path = <?php echo json_encode($field);?>;