How to pass javascript variable in PHP?

Discussion on PHP Scripting
no avatar
shruti_sharma
 
Posts: 2
Joined: Sun Sep 02, 2012 7:17 pm

How to pass javascript variable in PHP?

by shruti_sharma » Sun Sep 02, 2012 8:54 pm

Hi

How to pass javascript variable in PHP?

Any help?

no avatar
daniel88
 
Posts: 11
Joined: Thu Dec 27, 2012 12:37 pm
Location: VIET NAM

»ï¿½

by daniel88 » Tue Jan 22, 2013 11:03 am

You cannot pass variable values from the current page javascript to the current page PHP code... PHP code runs at the server side and it doesn't know anything about what is going on on the client side.

You need to pass variables to PHP code from html-form using another mechanism, such as submitting form on GET or POST methods.

no avatar
m3hr24d
 
Posts: 1
Joined: Sun Jun 23, 2013 12:59 pm

Re: How to pass javascript variable in PHP?

by m3hr24d » Sun Jun 23, 2013 1:22 pm

Code: Select all
function myJavascriptFunction() {
  var javascriptVariable = "John";
  window.location.href = "myphpfile.php?name=" + javascriptVariable;
}

Return to PHP Script