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
  • 75,622
  • 18
  • 128
  • 150
Dipak
  • 57
  • 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,955
  • 14
  • 48
  • 66
pa1geek
  • 258
  • 7
  • 19