setInterval isnt working reliably for asp.net application

I have some code as follows:
My goal is to have a timer in java script that does some periodic checks and submits the form.  I have used some alerts to see if my javascript is working.  THe first time I tried the code below I got an alert window every second.  But sadly, re reunning I dont see any alerts at all.  If I lower the timeout i might get one alert.

I tried changing the alert to document.Form1.submit(); since that is what i ultimately want, but I dont see a form submission either.  the html for the page:
      <body MS_POSITIONING="GridLayout">
            <form id="Form1" method="post" runat="server">


The working c# code:  (at least I get my alert if its added to check()
              if(!Page.IsPostBack)
               {
                    SubmitButton.Attributes.Add("onclick","check();");
               }

The not working very well javascript:
function check(){
     setInterval("checkStatus()",1000)
}
function checkStatus(){
     alert('checkfile');
}
LVL 1
lynx2sw1Asked:
Who is Participating?
 
eguilhermeConnect With a Mentor Commented:
i suggest sticking with setInterval, but i suggest aswell clearing ur interval before anything

var intervalID
function check(){
     intervalID = setInterval("checkStatus()",1000)
}
function checkStatus(){
    if(whatIwant==true)
    {
        clearInterval(intervalID)

    }
}

0
 
FDzjubaCommented:
use
setTimeout("doForwardStep()", 2000);

instead of
setInterval("doForwardStep()", 2000);


0
 
FDzjubaCommented:
and to get repeatative timers  call timer function from initialize function again like this,

function checkStatus(){
     alert('checkfile');
     check();
}
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
lynx2sw1Author Commented:
Modified as per below.  I get a few form submissions , maybe 5, and then no more.
Do I need to be clearing and resetting something?
var t
var count=0;
function check(){
      setTimeout("checkStatus()",2000);
}
function checkStatus(){
      document.Form1.submit();
      check();
}
0
 
FDzjubaCommented:
is your page reloading, then stick the setTimeout in the body of the document which will trigger itself everytime the page is reloaded, no need for functions.

0
 
lynx2sw1Author Commented:
well, the real goal is to periodically do a test, and only reload when the test indicates.
0
 
lynx2sw1Author Commented:
oops.  I meant to award FDZJuba.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.