Forum Moderators: open

Message Too Old, No Replies

setTimeout not firing.

executes once and does not restart.

         

gene292

10:39 pm on Feb 17, 2011 (gmt 0)

10+ Year Member



Below is a test code - any ideas why it runs only once?

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-5" />
<script type="text/javascript">
window.onload = createSlideShow;

function createSlideShow()
{
var slideIndx = 0;
//setTimeout("showCount()", 3000);
showCount();

function showCount()
{
slideIndx = (slideIndx +1) % 3;
var inp = document.getElementById('xxId');
setTimeout("showCount()", 3000);
inp.value = slideIndx + 1;
alert( slideIndx );
}
}
</script>
</head>

<body>
<input id="xxId" name="xx" class="ftext" type="text" value="0"/>
asdf
</div> <!-- end id="content"> -->
</body>
</html>

gene292

2:20 am on Feb 18, 2011 (gmt 0)

10+ Year Member



It looks like the problem is in the line:
setTimeout("showCount()", 3000);

When I changed it to
setTimeout(showSlides, 5 * 1000);
it worked as intended.

Are so many inernet references wrong?
Example: [w3schools.com...]

daveVk

6:06 am on Feb 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You seem to have } misplaced

function createSlideShow()
{
var slideIndx = 0;
//setTimeout("showCount()", 3000);
showCount();
}

function showCount()
{
slideIndx = (slideIndx +1) % 3;
var inp = document.getElementById('xxId');
setTimeout("showCount()", 3000);
inp.value = slideIndx + 1;
alert( slideIndx );
}