J
John Yopp
I seem to be have problems with what appears to be variable scoping. If
I define a constant in my main HTML page, I do not seem to be able to
reference it within functions in JavaScript include files.
For instance, I receive the following errors:
Error: CONST0 is not defined
Source File: test1.js
Line: 3
Error: CONST0 is not defined
Source File: test2.js
Line: 4
Error: document.getElementById("div1") has no properties
Source File: jstest1.html
Line: 18
=========== BEGIN jstest1.html ======================
<html>
<head>
<script type="text/Javascript" src="test1.js"></script>
<script type="text/Javascript" src="test2.js"></script>
<script type="text/javascript" language="JavaScript">
<!--
const CONST0 = "foo";
document.getElementById("div1").innerHTML = 'This is from
test1.html:<br>CONST0 = ' + CONST0 + "<br>" +
'CONST1 = ' + CONST1 + "<br>" +
'CONST2 = ' + CONST2 + "<br>" ;
//-->
</script>
</head>
<body bgcolor="white">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</html>
=========== END jstest1.html ======================
=========== BEGIN test1.js ======================
const CONST1 = "This is from test1";
document.getElementById("div1").innerHTML = "This is from
test2.html:<br>CONST0 = " + CONST0 + "<br>" +
"CONST1 = " + CONST1 + "<br>" +
"CONST2 = " + CONST2 + "<br>" ;
=========== END test1.js ======================
=========== BEGIN test2.js ======================
const CONST2 = "This is from test2";
document.getElementById("div1").innerHTML = "This is from
test1.js:<br>CONST0 = " + CONST0 + "<br>" +
"CONST1 = " + CONST1 + "<br>" +
"CONST2 = " + CONST2 + "<br>" ;
=========== END test2.js ======================
I define a constant in my main HTML page, I do not seem to be able to
reference it within functions in JavaScript include files.
For instance, I receive the following errors:
Error: CONST0 is not defined
Source File: test1.js
Line: 3
Error: CONST0 is not defined
Source File: test2.js
Line: 4
Error: document.getElementById("div1") has no properties
Source File: jstest1.html
Line: 18
=========== BEGIN jstest1.html ======================
<html>
<head>
<script type="text/Javascript" src="test1.js"></script>
<script type="text/Javascript" src="test2.js"></script>
<script type="text/javascript" language="JavaScript">
<!--
const CONST0 = "foo";
document.getElementById("div1").innerHTML = 'This is from
test1.html:<br>CONST0 = ' + CONST0 + "<br>" +
'CONST1 = ' + CONST1 + "<br>" +
'CONST2 = ' + CONST2 + "<br>" ;
//-->
</script>
</head>
<body bgcolor="white">
<div id="div1"></div>
<div id="div2"></div>
<div id="div3"></div>
</body>
</html>
=========== END jstest1.html ======================
=========== BEGIN test1.js ======================
const CONST1 = "This is from test1";
document.getElementById("div1").innerHTML = "This is from
test2.html:<br>CONST0 = " + CONST0 + "<br>" +
"CONST1 = " + CONST1 + "<br>" +
"CONST2 = " + CONST2 + "<br>" ;
=========== END test1.js ======================
=========== BEGIN test2.js ======================
const CONST2 = "This is from test2";
document.getElementById("div1").innerHTML = "This is from
test1.js:<br>CONST0 = " + CONST0 + "<br>" +
"CONST1 = " + CONST1 + "<br>" +
"CONST2 = " + CONST2 + "<br>" ;
=========== END test2.js ======================