SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 26th, 2004, 02:00 AM
ocean ocean is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 18 ocean User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
settimeout problem in two nested loops

hi im trying to make a input box have its value changed to several texts got from a different text area from time to time..and before the value of the input box changes i want to use a counter in a div to show countdown and slow down change of text and bgcolor of the div with the countdown in it....but im totally lost...the inputs boxes value changes before it even goes to the loop for changing the number in the div and the number doesn't change from time to time it just waits for the given time and goes straight to the last number and thats it...

here is the code
Code:
<head>
<script type="text/javascript">
<!--
function timer(num){
	
	counter = document.getElementsByTagName('div')(0)
	newtext = document.createTextNode(num);
	counter.removeChild(counter.firstChild);
	
	counter.appendChild(newtext);
	
	changebgcolorofdiv();
	}

function changebgcolorofdiv(){
	
	var divcolor = document.getElementsByTagName('div')(0).style.back  groundColor;
	var divcolor2 = divcolor.split('#');
	divcolor3 = parseInt(divcolor2[1],16);
	divcolor3 = divcolor3+10;
document.getElementsByTagName('div')(0).style.back  groundColor = divcolor3;	
	
	
}
//-->
</script>

</head>

<body>
<script type="text/javascript">
<!--
function changetext(){
	var giventext = textarea1.value.split('\n');
	
	
	for(i=0;i<hackpass.length;++i){
	document.textbox2.value = giventext;	//Here im trying to change the text in a loop
	for(n=0;n<10;n++){
		setTimeout(timer(n),5000);//here im trying to slow down this loop and the parent loop before the text is changed in the textbox2 and to make the countdown
	}
				
	
	
	}
}
//-->
</script>

<a href="javascript:changetext();"> Changetext</a><!--link to changetext()-->
<div name="counter" style="margin-top: 20px;background-color:aaaaaa; border-style:solid; border-width:1px; border-color: 225500; width: 100px; height: 100px"></div><!--Div for the countdown to show-->
<input type="text" name="textbox2" size=20><br><br><!--this is the input box where the text should be changed a short time after time with delay-->
<textarea name="textarea1"></textarea><br><br><!--textarea where i can enter the texts i wish to show in the textbox2 time after time with a delay-->
</body>


Looking forward to your help

Reply With Quote
  #2  
Old August 8th, 2005, 01:38 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 541 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 15 m 6 sec
Reputation Power: 3
setTimeout

this code
for(n=0;n<10;n++){
setTimeout(timer(n),5000);
}
is resetting the setTimeout with each pass through the loop. The loop is being passed through before the setTimeout has a chance to "time". It's OK to call the timer function inside the changetext function, but the setTimeout should call the function it's inside of
ie. setTimeout(changetext(),5000);

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > settimeout problem in two nested loops


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway