|
 |
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
|
|
07-02-2006, 08:38 AM
|
PM User |
#1
|
|
New Coder
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
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!
|
|
|
|
07-02-2006, 08:53 AM
|
PM User |
#2
|
|
Senior Coder
Join Date: Mar 2005
Location: Portsmouth UK
Posts: 4,358
Thanks: 3
Thanked 458 Times in 445 Posts
|
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>
|
|
|
07-02-2006, 09:06 AM
|
PM User |
#3
|
|
New Coder
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
legend - that was actually a typo, i was using 20
similar problem to my last error.
|
|
|
07-02-2006, 09:07 AM
|
PM User |
#4
|
|
Senior Coder
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
|
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.
|
|
|
07-02-2006, 09:57 AM
|
PM User |
#5
|
|
New Coder
Join Date: Dec 2005
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
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?
|
|
|
07-03-2006, 03:34 PM
|
PM User |
#6
|
|
Senior Coder
Join Date: Jul 2005
Location: New York, NY
Posts: 1,084
Thanks: 4
Thanked 19 Times in 19 Posts
|
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.
|
|
|
 |
Jump To Top of Thread
| Thread Tools |
|
|
| 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
HTML code is Off
|
|
|
All times are GMT +1. The time now is 04:13 AM.
|
Advertisement Log in to turn off these ads. |
|
|
|
|
|
|
|
|
|
|