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

Frank lists at frankmarion.com
Sat Mar 8 15:56:01 CST 2003

I have an external js page chock full of functions, but I find that I'm
having to repeat some common variables, specifically div id's and such.

         var myform = document.getElementById("myForm");
         var mydiv= document.getElementById("myUniqueDiv");
         var myspan= mydiv.getElementsByTagName("span");

I've tried setting my variables at the top of the page, hoping that each
function could make use of it, but apparently that's not the case.

I would like to be able to remove them from each function, just to tidy
things up, and not have to pass them manually as arguments each time.

Can someone suggest how I might set them up as globals?


More information about the thelist mailing list