Click to See Complete Forum and Search --> : global variable not global?


Technetium
06-28-2003, 07:56 PM
In the HEAD tag of the page, I have a short script block that just assigns a variable using:

<script src="jscript.js">
<!--
counter=0;
//->
</script>

From the tutorials I've read, this variable should be accessable from the rest of the page. I have an image with an onmouseover event, and for test purposes, this simply reads:

onmouseover="window.alert(counter)"

But nothing happens when I test it. Is there something else I need to do to be able to access the variable? I have tried moving the variable initialization into the top line of the .js file, thinking that maybe I had to have all my javascript in one place or the other, but it didn't help.

I am running Mozilla 1.2.1, and I do have Javascript fully enabled in the preferences.

jeffmott
06-28-2003, 08:02 PM
<script src="jscript.js">
<!--
counter=0;
//->
</script>HTML 4.01 Specification
If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.

chrismartz
07-03-2003, 02:22 PM
what are you trying to get the counter to show other that 0

Jona
07-03-2003, 02:33 PM
I'd do something like this:


<script type="text/javascript">
<!--
var counter = 0;
//-->
</script>
<script type="text/javascript" src="jscript.js"></script>


[J]ona

Technetium
07-03-2003, 02:59 PM
Thanks for all the advice, I have it working just fine now.

Jona
07-03-2003, 03:35 PM
Originally posted by Technetium
Thanks for all the advice, I have it working just fine now.

You're welcome for what I did. :)

[J]ona