Forum Moderators: open
When I try to refer to the variable, it's not null, just empty, so the second file is apparently aware of the declaration. However, it doesn't see that its value has been updated. Is there a way I can use the DOM to retrieve the current value of the variable?
Thanks!
g.
Two script blocks/files are the same as one large one, with the exception that you can't reference a function declared in the second block in inline script in the first. This exception doesn't come into play here.
Of two external scripts, the second isn't supposed to start executing until after the first. Very occasionally I have seen buggy hints that suggest that something other was happening.
In the second script, if you try testing your variable:
if(myVar){...}
and you get away without an error message, then it has indeed been declared (and at least set to undefined) somewhere else. Odd.
if (resultSets) alert("variable exists"); If I use this one:
if (resultSets.length) alert("variable exists"); Here's some abbreviated code...
Import 1
var resultSets = new Array();
function setTableWidth() {
if (resultSets.length > 0) {
...
}
} Import 2
window.setTableWidth = new function()
{
if (resultSets) alert("variable exists");
if (resultSets.length > 0) {
...
}
} Inline
<script type="text/javascript">
resultSets.push
('frmTest:_id1','divHeadfrmTest:_id1','divScrollfrmTest:_id1');
window.onload = setTableWidth;
</script>
window.setTableWidth = new function()
{
..blah..
}
// from this point on..
setTableWidth isn't a function it's an plain "custom" JS object. The anonymous function is it's constructor.
Either (1) Take away the
[blue]new[/blue] operator, or (2) write it as a function declaration in the usual way (Same as the function in the block above. It will still override it).