...

View Full Version : asynchronous setInterval() problem



gsriar
08-03-2007, 01:13 PM
hi all

i have this code snippet
<script type="text/javascript">
var a= setInterval ( "countText0()", 1000 );
var b= setInterval ( "countText1()", 2000 );
var count=0;
var count1 =0;
function countText0 ()
{
document.getElementById("Text0").value =count;
count=count+1;
}
function countText1 ()
{
document.getElementById("Text1").value =count1;
count1=count1+1;
}


</script>

<input type="text" id="Text0" runat="server" value="" />
<br />
<input type="text" id="Text1" value="" />

problem is that functions countText0 and countText0 are not mutually indipendent

My application needs there independence
i need there asynchronous calls

can someone please help

Kor
08-03-2007, 10:40 PM
I guess you need the setTimeout() method instead:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
/*<![CDATA[*/
var count=0;
var count1=0;
function countText0(){
document.getElementById("Text0").value =count;
count+=1;
setTimeout('countText0()',1000);
}
function countText1(){
document.getElementById("Text1").value =count1;
count1+=1;
setTimeout('countText1()',2000);
}
onload=function(){
countText0();
countText1();
}
/*]]>*/
</script>
</head>
<body>
<div>
<input type="text" id="Text0" runat="server" value="" />
<br />
<input type="text" id="Text1" value="" />
</div>
</body>
</html>


Is this what you want?

gsriar
08-04-2007, 09:28 AM
this solved my problem

how may i nominate u as useful

i clicked on up(here) link
but did not found any area to post my suggetion

please tell procedure

thanx

Kor
08-04-2007, 04:25 PM
this solved my problem

how may i nominate u as useful

i clicked on up(here) link
but did not found any area to post my suggetion

please tell procedure

thanx
Nrver mind... The Admin has just ended the former nomination page, but he has not started yet a new one... Tx anyway ;)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum