'Object expected' using external JS
<p>I have a bit of code that works fine if it is added to a script tag on a page. I've moved it into a seperate JS file (in the same folder as the HTML page) but I get an 'Object expected' error anytime I try to call it.</p>

<p>This is my HTML page:</p>

<pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
    &lt;title&gt;Untitled Page&lt;/title&gt;
    &lt;script type="text/javascript" src="Jscript1.js" /&gt;
    &lt;script type="text/javascript"&gt;
        function t()
        {
            nsTest.test();
        }

        function t2()
        {
            nsTest.test2();
        }
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;input type="button" value="test" onclick="t()" /&gt;
    &lt;input type="button" value="test2" onclick="t2()" /&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>and this is my JS file:</p>

<pre><code>var nsTest = function ()
{
    var test = function ()
    {
        alert('nsTest.test');
    }

    var test2 = function ()
    {
        alert('nsTest.test2');
    }

    return {
        test: test,
        test2: test2
    }
} ();
</code></pre>

<p>I'm sure that I'm missing something really simple and obvious but I'm pretty new to JS and I've been going round in circles for a couple of hours at this point. </p>

<p>Can somebody please let me know what I'm doing wrong?</p>

<p>Thanks,</p>

<p>David</p>
