1

it is possible to call PHP function using HTML element as call to JavaScript function, as

<?php

function fname() { code to be excuted }

?>

<input type="button" value="call php function" onclick="fname()" />

I tried what is written but it was not successful.

Amal Murali
  • 73,160
  • 18
  • 123
  • 143
Dipak
  • 49
  • 1
  • 3
  • 4
    It doesn't work like that. You can't execute a PHP function directly using `onclick` handlers. Either write the function in JavaScript, or use AJAX to handle these. – Amal Murali Feb 16 '14 at 05:06
  • PHP is on the server, and Javascript is on your computer. You cannot trigger PHP functions without submitting data to the server. You can do something like that – pa1geek Feb 16 '14 at 05:07

1 Answers1

0

You can try to do something like this instead:

<?php
    function f() {
        echo "method called";
    }
?>

<form action="" method="post">
    <input type="submit" name="submit" value="Submit" />
</form>

<?php
    if (isset($_POST['submit'])) {
        f();
    }
?>
Angel Politis
  • 10,488
  • 13
  • 45
  • 63
pa1geek
  • 248
  • 6
  • 19