Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

defining global variables

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.
[181 byte] By [paulbarrett] at [2007-11-11 7:56:56]
# 1 Re: defining global variables
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>
bschaettle at 2007-11-11 23:35:00 >
# 2 Re: defining global variables
Just declare your variable outside of any function, and it's global.
JPnyc at 2007-11-11 23:35:53 >
# 3 Re: defining global variables
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"
}
dev_j at 2007-11-11 23:37:03 >