Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having a problem passing parameters

    My code isn't working and I'm trying understand if I'm reading it correctly

    1. Clicking on Div calls function

    Code:
        <div id="getNum">GET NUM</div>
    
            $(document).ready(function(){
        	    $("#getNum").click(function(){
                    makeid(17);

    2. makeid() is called and the number 17 is passed

    Code:
          function makeid(num){ // function called & parameter passed
    	  var text = '';    // var inside the for-loop is declared
    	  var loopNum = num; // the parameter is stored in a variable
    	  var chooseLetters = "abcdefghijklmnopqrstuvwxyz";
    
    	for( var i=0; i < loopNum; i++ ) 
    	  text += chooseLetters.charAt(Math.floor(Math.random() * chooseLetters.length));
    	  return text;
    		    
    	} // END function makeid();

    3. The returned result from function makeid() is stored in a variable

    var mytext=makeid();

    4. The variable mytext is written to another div.

    $("#showNum").html(mytext).css('textTransform', 'capitalize');

    I think I'm beginning to understand this. And yet. It's not working.

    Thanks for any insight.

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    var mytext=makeid();
    
    
    $("#showNum").html(mytext).css('textTransform', 'capitalize');
    this will get you nothing as you havent supplied makeid with a number.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •