[thelist] Javascript: Global variables in external .js?

Hassan Schroeder hassan at webtuitive.com
Sat Mar 8 19:51:01 CST 2003

Frank wrote:

> window.onload=init(); will indeed run the init() function, but will not
> allow the other functions to share the variables but this.onload=init();
> does.
> I have no idea why. Do you?

I'll guess you're getting some other (unrelated) error. Here's a
quick abbreviated test case:

<script type="text/javascript">
var mydiv;

function init()
     mydiv= document.getElementById("myUniqueDiv");
function reveal()

<form id="myForm">
	<input type="button" value="reveal" onclick="reveal();" />

<div id="myUniqueDiv">foo</div>


When the button's clicked, I get a popup with 'foo' in Moz 1.3b and
IE 5.5 (Win). If that doesn't work for you, let us know what OS and
browser and, uh, I dunno what else...

Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.

More information about the thelist mailing list