homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Can i use PHP variable in Javascript?

Msg#: 4516753 posted 11:55 am on Nov 7, 2012 (gmt 0)

I have a php Variale..I want to pass the php variable to the java script ...How come it possible?



WebmasterWorld Senior Member swa66 us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4516753 posted 1:13 pm on Nov 7, 2012 (gmt 0)

First off:
- PHP runs on the server.
- JavaScript runs in the browser.

To make the two interact, you do have a number of options.

The simplest way is to output the JavaScript from a PHP script so that the data accessible to PHP can be accessed in JavaScript as well (by just including it in an appropriate spot in the output). This is obviously just a one-time, single direction event.

The more complex interaction is where it's possible to send requests to a PHP script on the server from JavaScript and get data back and process it on the client side - all within a single page and possibly even multiple times, based on user input etc. This is what's commonly called AJAX.


Msg#: 4516753 posted 5:29 pm on Nov 7, 2012 (gmt 0)

Thank u


Msg#: 4516753 posted 11:54 am on Dec 26, 2012 (gmt 0)

PHP is a Pre Hypertext Processor meaning it is dynamic and processed server side and before it is displayed by the browser.


WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4516753 posted 8:38 pm on Dec 26, 2012 (gmt 0)

Like the man said, it depends on what the meaning of "is" is. Do you need to pass a variable directly from Function A to Function B, or is it enough to stash a variable from Function A in a safe place where Function B can get hold of it later? If your user requests a second page-- or takes some action that makes the original page get redrawn-- you might even get a variable moving in the other direction, from js to php.

And then you need a backup plan in case the user doesn't have/use js, or if js and php aren't speaking to each other.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved