CoderZone.org

Category: >> PHP Code >> Call a PHP function when clicking on an HTML button Bookmark and Share

<< lastnext >>

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.

Also see:
» Javascript Include - allows dynami...
» Fastest javascript Trim() function
» Automatically find location of jav...
» Add and Remove classes in Javascri...
» Javascript Trim Functions
» Get Easter Date for any year in Ja...
» Parsing PHP in Javascript Files
» Multi-line variables and strings i...
» Reserved Words In Javascript
» A JavaScript implementation of the...
» Get Query String with Javascript
» Javascript "Fade In On Click&...
» Javascript Confirm Delete Prompt
» Get and set radio buttons with Jav...
» Get and set select lists with Java...
» Get week number
» PHP to JavaScript Array
» Pass vars to/from Javascript
» Javascript Cookie functions
» Check radio button selection

Comment: (none)

Author: CoderZone
Language: PHP
Highlight Mode: PHP
Last Modified: March 16th, 2009

<?php
 
$a="hello";
 
?>
<script>
function echoHello(){
 alert("<?php hello(); ?>");
 }
</script>
 
<?php
function hello(){
 global $a;
 echo $a;
 }
 
?>
 
<button onclick="echoHello()">Say Hello</button>
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 13