Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-16-2004, 07:54 AM   PM User | #1
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
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 08:24 AM..
Mr J is offline   Reply With Quote
Old 07-16-2004, 08:15 AM   PM User | #2
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
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
__________________
"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. "

Last edited by jamescover; 07-16-2004 at 08:34 AM..
jamescover is offline   Reply With Quote
Old 07-16-2004, 08:36 AM   PM User | #3
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 07-16-2004, 08:42 AM   PM User | #4
jamescover
Regular Coder

 
Join Date: Aug 2002
Location: USA
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
jamescover is an unknown quantity at this point
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
__________________
"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. "

Last edited by jamescover; 07-16-2004 at 08:49 AM..
jamescover is offline   Reply With Quote
Old 07-16-2004, 08:52 AM   PM User | #5
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
Thanks Glenngv works fine
Mr J is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:37 AM.


Advertisement
Log in to turn off these ads.