Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Receiving Array parameter from PHP to Javascript??

Status
Not open for further replies.

Lekoya

Programmer
Aug 4, 2006
6
ZA
Hi All,
Is it possible to create an Array in PHP and pass it on to Javascript();

I have created an array in php and want to pass it as a parameter to a javascript function.
When i print the array inside PHP i get the following :
Code:
Array ( [0] => 38
        [1] => 174
        [2] => 172
        [3] => 98
        [4] => 386 )

But After recieving an array inside a javascript function,
When i code :
Code:
  alert(ArryParam.length)
it diplays 1

Here is my little javascript function:
Code:
function loadData(Arr)
{
alert(Arr.length);
if (window.ActiveXObject)
}
When i code :
Code:
  alert(Arr[0]);
it displays 'Undefined'

Is it possible to create an Array in PHP and pass it on to Javascript();
If so , then how shoud i go about that.

Thanx in advance
 
this question is better suited for the php forum, i think.

you'll need to generate code for JavaScript, not pass an PHP array.

you can loop through your PHP code and generate the following code, which makes up a javascript array:

Code:
var a = new Array(38, 174, 172, 98, 386);

and you can the pass that array into you javascript function call.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top