Click to See Complete Forum and Search --> : defining global variables


paulbarrett
02-07-2006, 10:16 AM
how can i define a string array variable that an entire html document will be able to see, i.e. a global variable, that all functions can use, etc.

Please?

Thanks.

bschaettle
02-10-2006, 03:09 PM
Not sure what you mean by "an entire HTML document will be able to see", but if you paste this code above the <BODY> tag, the array will be available anywhere on the page:

<SCRIPT Language="JavaScript">
var WeekdayNames = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
</SCRIPT>

JPnyc
02-10-2006, 10:29 PM
Just declare your variable outside of any function, and it's global.

dev_j
02-26-2006, 09:40 AM
You may place the variable outside the function.
or place it inside a function but do not var it

var isVisible = "" (var is not necessary)

function func(){
var notVisible="xx";
isVisibleToo = "xx"
}