I just want to share this code of mine.
A lots of website said that we cannot run php function when you run javascript events commands.

Can you try my code...cheers!!!!

<?php
function myfunction(){
$x="I love PHP by Arman de Guzman de Castro!";
return $x;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = "<?=myfunction();?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="" name="" type="text" onChange="ILovePHP();"></form><p>
</body>
</html>

Try to type something on the textbox and see what will happen.

    What happens is that Javascript, not PHP, pops up an alert dialog.

    So you figured out how to use PHP to output the necessary Javascript code to make something happen client-side. Congratulations; I would tell you how many times that's been done before your test case, but I imagine that the number would be very, very large.

    "Lots of website[sic]" tell you that it's impossible to directly call a PHP function in an onchange field because... it is. PHP is a server-side language; all of its code is processed by a server somewhere on the planet that then spits out whatever the final result is to your browser, wherever in the world that may be. Then, the connection is severed - your browser is left to do its job, render whatever the server gave it. When your onchange event fires, it's your computer that interprets the Javascript code and executes it.

      Write a Reply...