从PHP调用函数(Javascript)

I have a javascript popup dialog box but is unable to utilize it within my php code. I tried everything I could think of but nothing works below is an example code snippet:

<?php
    $password = "sysadmin";

    if( isset( $_POST[ 'signin' ] ) )
    {
        if( $password == 'sysadmin' )
        {
            echo "<script type = 'text/javascript'>msgAlert( 'Congrats', 'Access Granted' );</script>";
        }
    }
?>

<html>
    <head>
        <title>Test for Javascript Function Call</title>
    </head>

    <body>
        <form action = "" method = "POST">
            <button name "signin" type = "submit">Sign In</button>
        </form>

        <script type = "text/javascript">
            function msgAlert( title, text )
            {
                alert( title + " : " + text );
            }
        </script>
    </body>
</html>

the code above is just a sample test, if I can get the code above to work maybe I can to call a boostrap javascript popup dialogbox cause it is really boring to use the default window.alert() dialog box. So what is wrong with the code? why is it not calling the necessary function? what should I do to be able to get the code running smoothly.

on a side note, please no need to downpoint my question. This question may be redundant/stupid/annoying/unimportant and whatever to you, but I am new to web development so it is pretty much important to me...thanks for the help

Theres another mistake in your js code: You try to call the function before the dom is loaded. That may causes the problem. Do sth like this in your js:

window.onload=function(){msgAlert("test");};

You need to include the Javascript function inside php tags. Otherwise the Javascript function call will go out of scope. here's an example. N:B the code is not tested.

<?php
    $password = "sysadmin";
    if( isset( $_POST[ 'signin' ] ) )
        {
            if( $password == 'sysadmin' )
                {

                    echo "<script type = 'text/javascript'>
function msgAlert( title, text )
            {
                alert( title + ' : ' + text );
            }msgAlert( 'Congrats', 'Access Granted' );</script>";
                }
        }
?>
   <!-- remaining html -->