how do I import from a PHP array in a Javascriptarray

F

Frits v/d Laan

Hi
I cannot figure out how to import an array from PHP into Javascript

MyPHPcode is like this

<?php
$i=0;
While ($i < $num) {
$PHPvar= (" $PHPvar \" $Mystring[$i] \" , ");
$i++;
}
?>

The ouput of $Mystring is: "string1","string2","etc"," " (the
last empty string is added later on in the function:


This is exactly what Javascript expects in an array, however I get no
output in Javascript this way.


transfering data:

<INPUT TYPE= "hidden" ID= "PHP2JS" VALUE="<?php echo( $c);?> ">

Javascript:

<script type="text/javascript">

var text=PHP2JS.value;
document.write(text);

myarray = new Array(text);

for etc.
</script>

When I replace the \" with nothing (in the PHP part) it works in
the - document write(text) - and all data is loaded into
myarray(0) but I need the " " .

does someone have a better idea?

Thanks

Frits
Netherlands

Frits v/d Laan
Biologische tuinplanten kwekerij
http://fvanderlaan.nl
 
D

Danny

<script type="text/javascript">
<?php
echo "var myjsArr=split(" . implode(",", $Mystring) . ")"; //
$Mystring being the php array object
?>

</script>
as for addressing an IDed object in js, you use
document.getElementById('WHATEVERIDHERE');


Danny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,316
Latest member
naturesElixirCBDGummies

Latest Threads

Top