Page 1 of 1

Passing Data from PHP to Javascript

Posted: Mon Nov 08, 2004 12:37 am
by youngj
Hi,
I want to pass an array of values from PHP to Javascript without using hidden fields.

Please somebody help.

Posted: Mon Nov 08, 2004 3:00 am
by phpScott
use php to create a variable that will hold the values you want in javascript so that when the page loads you just echo out those values like a normal php but the variable will contain correct synatax for javascript ex.

Code: Select all

<?php
for($x=0; $x<$someNum; $x++)
{
  $jsArray.="//js array values";

}
?>

//html header stuff

<script language="javascript">
<? php echo $jsArray; ?>
</script>
//rest of html here
make sense?