javascript - Use same variable that is defined in another function -
this may seem simple less experienced javascript. have 2 functions. 1 called when upload begins. next called when upload ends.
in first function, variable created, unique id used upload. best way go reusing in second function since not global? reason defined within function because every time user clicks upload button, function called , new id created upload, why not want define outside because same id served second upload unless page refreshed.
anyone got suggestions?
function uploadstart() { function makeid() { var text = ""; var possible = "abcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; < 32; i++ ) text += possible.charat(math.floor(math.random() * possible.length)); return text; } var rand_id = makeid(); } uploadfinish(){ //rand_id undefined }
try declaring rand_id in global scope (before everything)
var rand_id; function bla....
Comments
Post a Comment