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
    Regular Coder
    Join Date
    Apr 2007
    Posts
    179
    Thanks
    17
    Thanked 0 Times in 0 Posts

    pass parameter to call back function

    Main function:

    {
    var param1="test";

    var param2= new test();


    ajax.onreadystatechange = callBackFunc;

    ajax.open(...)

    }


    function test(){...}

    function callBackFunc(?){


    }


    How I can pass the param1 and param2 to the callBackFunc function?



    Thanks

    Scott

  • #2
    ess
    ess is offline
    Regular Coder
    Join Date
    Oct 2006
    Location
    United Kingdom
    Posts
    866
    Thanks
    7
    Thanked 30 Times in 29 Posts
    either make param1 and param2 global by declaring them outside these functions

    Code:
    var param1="test";
    
    var param2= new test();
    
    Main function:
    {
    ajax.onreadystatechange = callBackFunc;
    ajax.open(...)
    }
    function test(){...}
    function callBackFunc(?){
    }
    or, append param1 and param2 within the body of callBackFunc(param1, param2) when making the call back.

    For example,
    Code:
    function callBackFunc(param1, param2){
    	alert( param1 + " " + param2);
    }
    window.onload = callBackFunc("Hello", "world");
    an alert message will appear when the window is loaded...which is a call back in this case I guess.

    Cheers
    ~E


  •  

    Posting Permissions

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