External JS not working when called from PHP created HTML
<p>I have a PHP script that creates HTML by calling PHP class that I have created.  The class creates all the HTML tags one of which is a  tag that loads an external JS file. When I try to access the functions from said file nothing happens. Any Ideas?</p>

<p>index page:
    

<pre><code>function main(){
    $content = "Heres some text for you";

    $page = new Page($title="MyTitle", $script="external.js", $content=$content)
    echo $page-&gt;toString();
}

function __autoload($className){
    require_once $className . '.class.php';
}
</code></pre>

<p>class page:
    

<pre><code>    //class constructor
    function __construct($title='untitled', $script='', $content='Default Page class page'){
    $this-&gt;title = $title;
    $this-&gt;script = $script;
    $this-&gt;stylesheet = $stylesheet;
    $this-&gt;content = $content;
    // $this-&gt;currentUser = $currentUser;
    }

    // creates tag structure for HTML pages
    function toString(){
    return &lt;&lt;&lt;END
            &lt;!DOCTYPE html&gt;
            &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
            &lt;head&gt;
            &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
            &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt;
            // Heres the link to the external JS file
            &lt;script type="text/javascript" src="$this-&gt;script"&gt;&lt;/script&gt;

            &lt;script type="text/javascript"&gt;
                 test();
            &lt;/script&gt;
            &lt;title&gt;$this-&gt;title&lt;/title&gt;
            &lt;link type="text/css" rel="stylesheet" href="$this-&gt;stylesheet" /&gt;
            &lt;/head&gt;
            &lt;body&gt;
        $this-&gt;content
        &lt;p id='content'&gt;page content&lt;/p&gt;
            &lt;/body&gt;
            &lt;/html&gt;
END;
    }// end toString function

} // end class Page
?&gt;
</code></pre>

<p>External JS:</p>

<pre><code>function test(){
    alert("ext. JS test works");
}
</code></pre>
