Forum : How can I pass a variable from Javascript to PHP?
Brief description  about Online courses   join in Online courses
View Abhijit  Paul 's Profile

How can I pass a variable from Javascript to PHP?

Hi,

Can any one tell me how to pass variable from Javascript to PHP....
Asked by Abhijit Paul | Nov 23, 2009 |  Reply now
Replies (1)
View teacher siliconindia 's Profile
Hi Abhijit Paul,

Please go though the code given below:

<?php
if (isset($_GET['width']) AND isset($_GET['height'])) {
// output the geometry variables
echo "Screen width is: ". $_GET['width'] ."<br />\n";
echo "Screen height is: ". $_GET['height'] ."<br />\n";
} else {
// pass the geometry variables
// (preserve the original query string
// -- post variables will need to handled differently)

echo "<script language='javascript'>\n";
echo " location.href=\"${_SERVER['SCRIPT_NAME']}?${_SERVER['QUERY_STRING']}"
. "&width=\" + screen.width + \"&height=\" + screen.height;\n";
echo "</script>\n";
exit();
}
?>


Hope you go the answer
Nov 23, 2009