Reputation: 53
Passing value JavaScript variable to PHP.
Example
JavaScript
Var ddd='aaaa'
PHP
if (ddd="aaaa"){do somehting...}
Upvotes: 2
Views: 7104
Reputation: 642
One way you can do that is to put it in the cookie:
var ddd = 'aaaa';
document.cookie = "ddd="+ddd; // the ddd in the "" is the name of the cookie
PHP
$ddd = $_COOKIE['ddd'];
if (ddd == "aaa") { do something... }
Upvotes: 0
Reputation: 14002
Javascript is a Client side scripting language that is only executed after the page is fully loaded. PHP on the other hand is an on-demand compiling script. It parses the PHP within the file and outputs the resulting HTML to the user's Browser.
Upvotes: 4
Reputation: 115
I have tested the following code and it have worked. So please test this code:
function aa()
{
var ddd='aaaa';
window.location.href="newpage.php?Result=" +ddd;
}
click a button then will call aa()
function and will go newpage.php where we get ddd variable value in Result variable
newpage.php:
extract($_GET);
echo $Result;
Upvotes: -1
Reputation: 968
In JS:
$.post('ajax.php',{'dddd' : dddd}, function(data){
});
In PHP
if(isset($_POST['dddd'])) $dddd = $_POST['dddd'];
Upvotes: 0