By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 629 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

how do I import from a PHP array in a Javascriptarray

P: n/a
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
Feb 4 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<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
Feb 5 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.