0

hi everyone,
I am in problem to get the array data from php to use it in js.


$data[0]=88;
$data[3]=44;
$data[4]=2232;

I want to use those data in js.


Can anyone help me ??

3
Contributors
3
Replies
5
Views
9 Years
Discussion Span
Last Post by adorosh
0
<?php
$data[0]=88;
$data[3]=44;
$data[4]=2232;
echo "
<html>
<head>
<script type=\"text/javascript\">
function test(){
	
alert('$data[0]');
}
</script>
</head>
<body onload=\"javascript: test();\">
</body>
</html>";
?>

This is how you can use php variables in your javascript. This is just an example.

0

thank you for your helping,but I need to first check the data ,If data exists then run the js code otherwise not.
this like:
first : read data from database .
second : check the data
third : if data exists then run js otherwise not.

i do it in the same file.but I want to simplify my code ,so I need to place the js code in the other file.
i just need if their have any possibility to get the array data of php in js.

0

You can get the JS script into some other file, but make this script use some global variable.
By this way you can parse needed array in PHP, then put the value on page and if the JS script included will find those, it will run.
It's hard code, but will work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.