Passing value JavaScript variable to PHP.
Example
JavaScript
Var ddd='aaaa'
PHP
if (ddd="aaaa"){do somehting...}
Passing value JavaScript variable to PHP.
Example
JavaScript
Var ddd='aaaa'
PHP
if (ddd="aaaa"){do somehting...}
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.
<script type='text/javacript'> block within the <body> tag for example. To ensure Javascript executes after page load, it would have to be in a onload handler.document.write('string');In JS:
$.post('ajax.php',{'dddd' : dddd}, function(data){
});
In PHP
if(isset($_POST['dddd'])) $dddd = $_POST['dddd'];
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;