I'm trying to pass a variable to a function but it isn't working.
Clicking on the DIV #getNum calls a function
<div id="getNum">GET NUM</div>
... calling function makeID() and passing the number 17
$(document).ready(function(){
$("#getNum").click(function(){
makeid(17);
});
});
very simple example below to show what's wanted.
function makeid(num){ // It doesn't work as the parameter isn't passed
var chooseLetters = "abcdefghijklmnopqrstuvwxyz";
var loopNum=num;
for( var i=0; i < loopNum; i++ ) // loopNum does not work!
text += chooseLetters.charAt(Math.floor(Math.random() * chooseLetters.length));
return text;
} // END function makeid();
/* working example */
function makeid(num){ // why can I not pass the parameter to the for loop?
//console.log(num); // console.log reads num!
var num = num; // variable num is not read!
var loopNum = num; // works if hard coded
var chooseLetters = "abcdefghijklmnopqrstuvwxyz";
for( var i=0; i < loopNum; i++ )
text += chooseLetters.charAt(Math.floor(Math.random() * chooseLetters.length));
//console.log(text);
return text;
} // END function makeid();