I'm an extreme novice when it comes to javascript, I have a simple onclick button that loads text into modal box. The thing about it is that it also invokes a php function. On page load or refresh the php function is automatically triggered without clicking the button! How can I make it so that the button must be clicked before invoking the php function.
EDIT: The proposed duplication answer that was provided explains the logic behind why my question doesn't work but doesn't offer steps to take to fix it nor a path to take to learn how to render my question properly. The answer I posted addressed my issues directly.
Ive gotten some tips from the following pages but i havent been able to put it together properly I suppose:
onclick event is executed immediately without clicking
onclick event ocurring without click event actually happening - js
HTML:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter" onclick="buildFunction()">
Javascript:
 <script>
        function buildFunction() {
            document.getElementById("package").innerHTML = "Initializing Powershell...</br>";
            document.getElementById("package").innerHTML += "Initializing Connection to Build Server...<br>";
            document.getElementById('package').onclick = function() {
                <?php buildPackage() ?>;
            };
        }
</script>
PHP Function:
function buildPackage()
{
    $serverName = "\\\\Server";
    $msiName = '"""""""""ARG1"""""""""';
    $installDir = '"""""""""ARG2"""""""""';
    $runCMD2 = "start powershell.exe psexec -accepteula -s -i 2 " . 
    $serverName . " cmd /c D:\path\to\app.hta " . $msiName . " " . 
    $installDir;
    $execCMD = shell_exec("$runCMD2");
    echo "Starting Build...<br>";
    echo $execCMD;
    echo "Build Complete";
}
