0

friends.

I have a PHP Class like this:

class DiffFunctions {
    function showMessage($msg){
        echo "<script type='text/javascript'>alert('$msg')</script>";
    }
}

and I have tried this code in PHP Page:

<?php
include_once './Classes/DiffFunctions.php';
$myFuns2 = new DiffFunctions();
?>
<button id="sendMsg" type="submit" onclick="$myFuns2->showMessage('You have clicked the button')">Click Here To Show The Message</button>

But It did not work!

  • 3
    You're combining server side programming with client side programming, it doesn't work like that. Instead, use a form and `if (isset($_POST['button']))` to then run the method. – Jamie Bicknell Jun 29 '16 at 20:13
  • $myFuns2->showMessage('You have clicked the button')">Click Here To Show The Message is php code running on the server and it should be inside `` tags. `onclick=""` requires javascript code running in the browser, not `php` code. – PaulH Jun 29 '16 at 20:18
  • PaulH, the button code is in html form code – Ma'd Sa'eed Jun 29 '16 at 20:19
  • Jamie Bicknell, How can I do it? – Ma'd Sa'eed Jun 29 '16 at 20:20
  • I want to run a php function on clicking on button, how can I do it? – Ma'd Sa'eed Jun 29 '16 at 20:35

0 Answers0