seventheyejosh Posted April 23, 2009 Share Posted April 23, 2009 hello all. my question is this. is there a way to create a variable in one function and have it availible in another? like: function one(){ var one=1; } then have it useable in function 2? function two(){ alert('value of one is '+one); } thanks to all Link to comment https://forums.phpfreaks.com/topic/155381-moving-variable-from-function-to-function/ Share on other sites More sharing options...
Psycho Posted April 23, 2009 Share Posted April 23, 2009 You issue deal with variable scope. If you initialize a variable within a function, then that variable only has scope in that function. To make a variable have global scope, then declare it outside of the functions //Declare the variable var one; function one() { var one=1; } function two() { alert('value of one is '+one); } two(); //Will alert "Value of one is 1" Link to comment https://forums.phpfreaks.com/topic/155381-moving-variable-from-function-to-function/#findComment-817703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.