@Declan1991Aug 02.2010 — #Either that, or declare voltage globally first (i.e. var voltage in global scope), or use window.voltage from anywhere (my preferred option). Furthermore, if statements don't form a closure, so if the if statement is in global scope (which it probably isn't but it'll illustrate the point), var voltage would create a global variable.
@Sterling_IsfineAug 02.2010 — #I wish to declare a global variable, but only if a certain condition is met. For example:
[CODE] if (type1a == "voltage") { voltage = document.f1.value1.value; } [/CODE]
except that now it is not global because it is contained within an if statement. [/QUOTE]It's still global, however conditional variable declaration can be a hazardous practice. Subsequently-written code branches may assume the variable's existence, and testing may not always expose the error.