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 Quote 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" Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.