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 5 of 5

Thread: x is undefined

  1. #1
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts

    x is undefined

    Function test1 runs and alerts the argument values but when function 2 runs I get "x is undefined".
    If I declared the variables x y z either global or local I get an empty alert.

    Can someone educate me here

    <script>
    function test1(x,y,z){
    alert(x+" "+y+" "+z)

    setTimeout("test2(x,y,z)",2000)

    }


    function test2(x,y,z){
    alert(x+" "+y+" "+z)
    }

    </script>




    <a href="#null" onclick="test1(1,2,3)">Test 1</a>
    Last edited by Mr J; 07-16-2004 at 09:24 AM.

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, where are your definitions?



    http://devedge.netscape.com/library/...ce/frames.html



    undefined is a top-level property and is not associated with any object.

    A variable that has not been assigned a value is of type undefined. A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value.









    -james
    Last edited by jamescover; 07-16-2004 at 09:34 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Change this:

    setTimeout("test2(x,y,z)",2000)

    to:

    setTimeout("test2("+ x + "," + y + "," + z + ")",2000);

    In the case of string arguments:

    setTimeout("test2('"+ x + "','" + y + "','" + z + "')",2000);

    Not so readable, right?
    The same can be achieved without bothering for argument types using the function reference:

    setTimeout(function(){test2(x,y,z)}, 2000);

    But I think IE5 does not support that.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    setTimeout(function(){test2(x,y,z)}, 2000);

    But I think IE5 does not support that.



    It works in IE 5.0:

    undefined undefined undefined
    undefined undefined undefined


    I think, you posted it wrong:

    <script>
    function test1(x,y,z){
    alert(x+" "+y+" "+z)
    }
    setTimeout("test2(x,y,z)",2000); //outside the function


    function test2(x,y,z){
    alert(x+" "+y+" "+z)
    }

    </script>








    -james
    Last edited by jamescover; 07-16-2004 at 09:49 AM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Thanks Glenngv works fine


  •  

    Posting Permissions

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