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-02-2006, 08:38 AM   PM User | #1
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
function error.

hi again -

further problems with setTimeout, although it could be something else -

Code:
function taller(id, origheight, targheight, margin){
	if(origheight<targheight){
	  origheight = origheight + 2;
	  margin = margin - 1;
	  document.getElementById(id).style.height = origheight+"px";
	  document.getElementById(id).style.marginTop = margin+"px";
	  growtimer[1] = setTimeout("taller('+id+','+origheight+','+targheight+','+margin+')",0.5);
	}
}
is giving me errors.

if i comment out the set timeout line it causes no errors, and if i comment out the two document lines it again causes no erros. i'm confuddled!
limpsharp is offline   Reply With Quote
Old 07-02-2006, 08:53 AM   PM User | #2
vwphillips
Senior Coder

 
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,358
Thanks: 3
Thanked 458 Times in 445 Posts
vwphillips is a jewel in the roughvwphillips is a jewel in the roughvwphillips is a jewel in the rough
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
  <title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

var growtimer=[];

function taller(id, origheight, targheight, margin){
 if(origheight<targheight){
  origheight = origheight + 2;
  margin = margin - 1;
  document.getElementById(id).style.height = origheight+"px";
  document.getElementById(id).style.marginTop = margin+"px";
// time is in milliSeconds so 0.5 is not a valid time
  growtimer[1] = setTimeout(function(){ taller(id, origheight, targheight, margin); },10);
 }
}


/*]]>*/
</script></head>

<body>
<img id="Img1" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" onclick="taller('Img1', 100, 200, 5);"  />
</body>

</html>
__________________
Vic

God Loves You and will never love you less.

http://www.vicsjavascripts.org.uk/

If my post has been useful please donate to http://www.operationsmile.org.uk/
vwphillips is offline   Reply With Quote
Old 07-02-2006, 09:06 AM   PM User | #3
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
legend - that was actually a typo, i was using 20

similar problem to my last error.
limpsharp is offline   Reply With Quote
Old 07-02-2006, 09:07 AM   PM User | #4
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
Your original timeout line should have been like this

growtimer = setTimeout("taller('"+id+"' ,"+origheight+","+targheight+","+margin+")",10);

note the sinlge and double quotes around id
__________________
The silent one.

The most dangerous thing in the world is an idea.
The most dangerous person in the world is the one with an idea.
Mr J is offline   Reply With Quote
Old 07-02-2006, 09:57 AM   PM User | #5
limpsharp
New Coder

 
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
limpsharp is an unknown quantity at this point
Quote:
Originally Posted by Mr J
Your original timeout line should have been like this

growtimer = setTimeout("taller('"+id+"' ,"+origheight+","+targheight+","+margin+")",10);

note the sinlge and double quotes around id
i note them - but i don't understand them!

out of interest why would you need single and double quotes?
limpsharp is offline   Reply With Quote
Old 07-03-2006, 03:34 PM   PM User | #6
Beagle
Senior Coder

 
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
Beagle is an unknown quantity at this point
You are passing a string to setTimeout:

var id = x;
var origheight = 5;
var targheight= 6;
var magin = 3;

taller('x' ,5,6,3)

You need that wrapped in quotes:

"taller('x',5,6,3)"

If you use double quotes inside you get this:

"taller("x",5,6,3)"

But you didn't use any quotes and got this:

"taller(x,5,6,3)"

Where the value there becomes an undefined variable instead of a string.
Beagle 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 04:13 AM.


Advertisement
Log in to turn off these ads.