@TheBearMayMar 17.2005 — #You'll either have to make it a global variable (one defined outside of all functions), pass the value to the second function from the first, or store the value on the page (usually a hidden field) and read it from there.
@iceman2gauthorMar 17.2005 — #Now would this mean that if a variable were set within a fucntion I could make that variable a global one by doing var Variablename; outside the function.
@7studMar 17.2005 — #How do I got about accessing a variable located within another function?[/quote] Variables declared within a function are called "local variables", i.e. they are local to the function, and when the function ends, the local variables are destroyed and cannot be accessed anymore.
Variables declared outside of any functions are called "global variables", and they can be accessed from inside a function by referrring to them by their name.
There are several methods for declaring global variables: var x = 100; //global variable--it is declared outside any function
function A() { alert(x); }
function B() { alert(x); }
A(); B();
<i> </i>function A() { window["x"] = 100; //creates a global variable }
function B() { alert(x); }
A(); //creates the global variable B(); //accesses the global variable not recommended: <i> </i>function A() { x = 100; //if you don't use 'var', it creates a global variable }
function B() { alert(x); }
A(); //creates the global variable B(); //accesses the global variable
@iceman2gauthorMar 18.2005 — #Ok here's my delima. I have two drop menus. When an option is selected from either menu it updates prices on a page. The problem is i'm not sure how to update the price to take into account the selection of both menu selection.
i.e.
Color:
Red +2
Green +3
Blue +4
Size:
sm
med +2
lrg +3
ex-lrg +4
Currently i'm only able to update the price of the page with the selection of one of the two drop menus.
In js, undefined evaluates to false. It's a little confusing, but the last line will give you a "not defined or undefined error", but the way it works is if the variable hasn't been declared, you get an error, but if the variable has been declared, but it hasn't been assigned a value, then it is equal to "undefined".