I’ve been told not to use global variables.
I use one to turn off/on client side validation.
I use two more to conrol me drop-down menu.
If these should not be gloval variables where should I put them?
/*
Global
*/
var client_validation=1, // used to turn off/on client-side validation
menu_timer=0,
menu_elment=0;
window.onload=i0;
/*menu*/
function top_mouse_over(id)
{
bottom_mouse_over();
if(menu_element)menu_element.style.visibility='hidden';
menu_element=document.getElementById(id);
menu_element.style.visibility='visible';
}
function internal_time()
{
if(menu_element)menu_element.style.visibility='hidden';
}
function mouse_out()
{
menu_timer=window.setTimeout(internal_time, 500);
}
function bottom_mouse_over()
{
if(menu_timer)
{
window.clearTimeout(menu_timer);
menu_timer=0;
}
}
Header 1 // This makes more sense
Content
Header 1 // Than this
Content
It sounds to me like you those might be good candidates for globals. Globals are supposed to, well, be reserved for operations with broad implications for the app like controlling fundamental behavior across multiple pieces.
Now, if you want to create a “namespace” for them, it’s this simple:
Javascript doesn’t have real namespaces yet. Objects are used as a substitute for them until the next version of ECMAScript might get around to adding that feature.