Home >> Snippet List >> Snippet

Name
Call a PHP function when clicking on an HTML button
Description
Use the onclick() event listener in the button to call a Javascript function that will call the PHP function Note that if any variables are declared as GLOBAL in the PHP function, they must be assigned values before the Javascript function is parsed by the HTML interpreter
PHP Snippet
<?PHP
 
$a="hello";
 
?>
<script>
function echoHello(){
 alert("<?PHP hello(); ?>");
 }
</script>
 
<?PHP
FUNCTION hello(){
 GLOBAL $a;
 ECHO $a;
 }
 
?>