I am trying to produce a variable with one function and use it in another function, and then pass it again to another function from the second function. I have tried placing the variable inside the parenthesis in a multitude of ways but i cannot seem to get the variable to alert in the final function. JSfiddle
function randomNumber(randomstring) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 16;
var randomstring = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
//document.randform.randomfield.value = randomstring;
// alert(randomstring);
}
$("#btn").click( function() {
randomNumber();
//alert(randomstring);
update();
});
function update() {
alert(randomstring);
}
I have gone through several documents on Scope but i cannot see what i am not quite doing right here.