Passing Data from PHP to Javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
youngj
Forum Newbie
Posts: 1
Joined: Mon Nov 08, 2004 12:29 am
Location: India
Contact:

Passing Data from PHP to Javascript

Post by youngj »

Hi,
I want to pass an array of values from PHP to Javascript without using hidden fields.

Please somebody help.
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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?
Post Reply