How to equate a php variable with a javascript var

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
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

How to equate a php variable with a javascript var

Post by m2babaey »

Hi
I have some js code in my .php file
In the js code I have a variable "names"
I need to tell php the value of this variable and call it $names
How can I do that?
Thank you for your help
User avatar
getmizanur
Forum Commoner
Posts: 71
Joined: Sun Sep 06, 2009 12:28 pm

Re: How to equate a php variable with a javascript var

Post by getmizanur »

you can use ajax..
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: How to equate a php variable with a javascript var

Post by flying_circus »

m2babaey wrote:Hi
I have some js code in my .php file
In the js code I have a variable "names"
I need to tell php the value of this variable and call it $names
How can I do that?
Thank you for your help
Short answer is, you can't without making a new page request. PHP is processed before the javascript is. Therefor you cannot drink the glass of water before you pour the glass of water. Now, you can have PHP tell javascript the value of your variable.
Post Reply