...

View Full Version : how to call to a function(it is in javascript) from a php



kamkam
03-13-2009, 02:53 AM
Hi;
I'd like to ask how i can call a function which it is Javascript from php. Thanks



<?php
session_start();
$_SESSION['check']=1;
?>
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
alert("Hello World!");
}
</script>
</head><body>
<?php
if ($_SESSION['check']==1)
How i can call function displaymage()?????
else
echo "Bye";

?>

</body>
</html>

PappaJohn
03-13-2009, 03:11 AM
You cannot directly call a js function from php. php runs server-side while js runs client-side.

What you can do, is using your $_SESSION check, determine if the function should be called and, if so, echo the call to the function inside of the <body> tag (running it using the js on load event.

kamkam
03-13-2009, 05:12 AM
Thanks for your helpping.

i will do like that
echo "<BODY onLoad="javascript:displaymessage();">"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum