Write function in php executing with a button without having to post method to site

I can write a function in php.

How do I call it with a JavaScript Button in the same website without having to go to another php site?

<?php
    function fn1() {
          ...code
    }
?>
<script type="text/javascript">
    function javascriptbtn()
          ???
    }
</script>

<form name="myform">
<input type="button" name="Button" value="Calculate Julian Date" onclick="javascriptbtn()" />
</form>

Are you wanting it to execute without calling back to the server? Isn’t PHP a server-side language, so that’s not going to happen? (Learning here, so might be wrong).

Droopsnoot is right, PHP is executed on the server so there’s no way to run additional PHP code after the page has loaded without making another request to the server.

You’ve basically got two options:

  1. Use JS to make an AJAX call to the server, to get the results of a PHP script without having to reload the page.
  2. Write the functionality you want purely in JS.