Skip to content Skip to sidebar Skip to footer

How To Pass Value Javascript Variable To Php?

Passing value JavaScript variable to PHP. Example JavaScript Var ddd='aaaa' PHP if (ddd='aaaa'){do somehting...}

Solution 1:

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.

Solution 2:

In JS:

 $.post('ajax.php',{'dddd' : dddd}, function(data){
 });

In PHP

if(isset($_POST['dddd'])) $dddd = $_POST['dddd'];

Solution 3:

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... }

Solution 4:

I have tested the following code and it have worked. So please test this code:

functionaa()
{
    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;

Post a Comment for "How To Pass Value Javascript Variable To Php?"