I have a global variable a and I am using it inside a function and assigning a value to it. When I use this variable outside the function it gives me undefined.
Eg.:
var a;
function my_func(){
a=5;
}
console.log(a); //outputs undefined, how do I get the value 5 here
Why do I get undefined instead of 5?
It dint resolve my issue.
var id;
function set_id(myid){
id=myid;
}
function get_id(){
return id;
}
$("#btn").click(function(){
$.post("....", function(data){ //data reurns a JSON
set_id(id); //success!!
}
}
$("#show").click(function()[
console.log(get_id()); //doesn't work, how do I get this workin.. Where am I going wrong
}