Page 1 of 1

Passing variables between JavaScript and PHP

Posted: Mon Apr 12, 2004 11:32 pm
by Chris Corbyn
Hi,

I need to pass one or two variables from my PHP into a JavaScript on the same page.

I've had a read in the PHP manual and it does mention that you can pass variables from JavaScript into PHP but I cannot find a way to do the opposite.

Basically I'm trying to make a form which has a JavaScript function to change what is displayed when a user changes selections in the form. I need to use PHP to look up a filesize based on user input and then JavaScript to display what it finds (without using a submit button).

Thanks :-)

Posted: Mon Apr 12, 2004 11:34 pm
by Steveo31

Re: Passing variables between JavaScript and PHP

Posted: Tue Apr 13, 2004 12:51 am
by MarK (CZ)
d11wtq wrote:Hi,

I need to pass one or two variables from my PHP into a JavaScript on the same page.
You mean it just like this?:

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
  var myVar = <?= $phpVar ?>;
</SCRIPT>

Posted: Tue Apr 13, 2004 7:35 am
by magicrobotmonkey
in the form you can use onChange or onClick or whatever to redirect to self with vars in the URL