-4

Suppose i have a php class named "test.php" and inside of that class i have a function named "my_test()".

Now i want to call this function when my button is been clicked, so in my html class named "my_page.html" write like so ---

<button name="mytestbutton" type="button" onclick="my_test()" class="btn btn-primary btn-xs" value="my_test()">My Test</button>

But i need to write something so it recognize in my html that onclick it should do the function "my_test()". But how can i call my function in the html button, can any one have a solution for this problem.

Istiak Mahmood
  • 2,330
  • 8
  • 31
  • 73

1 Answers1

1

HTML, Javascript and the activity of your buttons run in your client (your web browser). PHP runs on the server. The only way you can send information to the server is by sending a new page request, form submission, or what is known as an AJAX request to the server, and have your PHP code pick up the data which has been sent to it

This data is normally picked up through the PHP 'superglobals' $_GET, $_POST, $_REQUEST etc.

Alternatively you can write my_test in JavaScript and have it run on the browser.

<script>
function my_test() {
   // your button code here
}
</script>

<!-- .. some HTML .... -->

<button name="mytestbutton" type="button" 
 onclick="my_test()" class="btn btn-primary btn-xs" value="my_test()">My Test</button>
vogomatix
  • 4,856
  • 2
  • 23
  • 46