Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    asynchronous setInterval() problem

    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

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I guess you need the setTimeout() method instead:
    Code:
    <!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?
    Last edited by Kor; 08-03-2007 at 10:43 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by gsriar View Post
    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
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •