PDA

View Full Version : Passing variables from PHP to...


russcrosbie2002
09-20-2002, 06:41 PM
Can a variable set in PHP be passed to Javascript code on the same page? (*.php) as I have noticed that the PHP parser supports Javascript.

(Yes, i am a noobie). :o

Regds

Russ.

Spookster
09-20-2002, 07:55 PM
PHP and Javascript cannot interact with each other directly. PHP runs on the server and javascript runs on the client machine.

What you can do however is use PHP to print out whatever javascript you need with whatever variables it needs passed to it:


<script language="Javascript">

<?php

echo "myjsvariable =" . $phpvariable;

?>

</script>


The result that is sent to the browser would be something like:

<script language="Javascript">
myjsvariable = 5;
</script>

c q
09-28-2002, 04:33 PM
somehow, I think its possible to do that usinghidden form fields. what say ?