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.
This is my HTML page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Page</title>
<script type="text/javascript" src="Jscript1.js" />
<script type="text/javascript">
function t()
{
nsTest.test();
}
function t2()
{
nsTest.test2();
}
</script>
</head>
<body>
<input type="button" value="test" onclick="t()" />
<input type="button" value="test2" onclick="t2()" />
</body>
</html>
and this is my JS file:
var nsTest = function ()
{
var test = function ()
{
alert('nsTest.test');
}
var test2 = function ()
{
alert('nsTest.test2');
}
return {
test: test,
test2: test2
}
} ();
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.
Can somebody please let me know what I'm doing wrong?
Thanks,
David
nsTest.nsTest.