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.

2
  • 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. Commented Feb 16, 2014 at 5: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 Commented Feb 16, 2014 at 5:07

1 Answer 1

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();
    }
?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.