|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Please i have this code to use and php array in a javascript function
<script language="JavaScript" type="text/JavaScript"> function cargar() { var xx=new Array() xx[0]="<?php echo $vector[0]; ?>" alert(xx[0]); } </script> and in the body tag <?php $vector[0]=1; $vector[1]=2; ?> The Cargar() function I call it from a botton. I got and error that says "string constant without end" or something lie that, at this line xx[0]="<?php echo $vector[0]; ?>" I tried to put ; at the end of the line, bot nathinsg seems to work Please help me, i just need to know how to use a php array in javascrit. Thanks.. |
|
#2
|
|||
|
|||
|
I got it!!!
Well, is me again!, The problem I had was the ubication of the javascript in my page,
so I put it at the end and it works!!! But Now I have a new problem, the position of the array that i want to use in javascript is a variable and i dont know how to use it. I put like this, but it doesn`t work. var p=0; xx[0]="<?php echo $vector["+p+"]; ?>" why???? please help me!!! |
|
#3
|
||||
|
||||
|
What is it you're t rying to accomplish by combining the PHP and JAvascript this way?
sometimes it gets complicated, and there's usually an easier way. Your problem above is because you're expecting PHP to understand the JAvascript variable... but remember that Javascript is called on the client side AFTER the PHP has already rendered... If you want to send a PHP array to a Javascript array, try this: PHP Code:
The above code is off the top of my head. It will hopefully lead you to some suplimentary answers. Reference:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Array in javascript from php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|