SetInterval called function crashes
I have an web app with some javascript functions. When you click a button it starts two "SetInterval" timers going, each calling a separate function. It calls one function first, and then it crashes. I get this error while debugging the page with VB.Net:
"Microsoft Javascript Error. Object Expected [Break][Continue]"
When I click "Continue" another error pops up:
"There is no source code available for the current location. [OK]"
When I step through the code, it crashes after exiting one of the timer functions. It's as if it has no place to go when it returns to caller.
Here's the script code stripped down to the bare ninimum (still crashes!)
Code:
// JScript File
var tmr1, tmr2
function HitScreen()
{
var a=0
} // crashers when it exits here.
function reCallServer()
{
var b=0
}
function btnStart_click() // This executes when I click the "Start" button
{
if (tmr1 == null)
{
var delay = parseInt(document.getElementById("txtRate").value)
tmr1 = setInterval("HitScreen()", delay)
}
if (tmr2 == null)
{
tmr2 = setInterval("ReCallServer()", 100)
}
return false
}
function btnStop_click()
{
if (tmr2 != null)
{
clearInterval(tmr2)
tmr2 = null
}
return false
}
The web page is actually an ASP.Net page with AJAX controls: A Script manager, and some slider controls, along with some buttons, text boxes, div boxes, etc. I don't know if any of that is a factor. The same errors occur when I debug with firefox.
Re: SetInterval called function crashes
I don't see any reason why this should crash.
A couple of questions...
1. When running only the code posted in Firefox, does it also crash?
2. Where do you define delay from the setInterval of tmr1?
3. You say it crashes exiting the HitScreen() function. Do you mean just running the function once, or when you call clearInterval(tmr1)?
Re: SetInterval called function crashes
When I load the page in firefox, the error console says "Error in parsing value for property'display'. Declaration dropped." The word "display" doesn't appear anywhere in my project directory. When I click the link, it shows the generated page, but my javascript stuff is missing. The code does not vanish using IE.
When I use the javascript debugger in firefox, I click the start button. I get "Error ``ReCallServer is not defined'' [xs] in file" over and over until I click the stop button. It's as if the code vanished after the button was clicked and the timer was started.
Delay is gotten from a text box which is controled by an AJAX slider control I've tried values from 1 to 101. The results are always the same. I've hard coded the value "10" and still get the same result.
In IE and VS. .NET (I've used both 2005 and Orcas Beta 1 for debugging) I click "Start one time. I trace the code for the start event handler, which initializes the two timers. Then it calls HitScreen, steps through the code, and then breaks upon exit from HitScreen.
Re: SetInterval called function crashes
Trying to alter CSS... Have you tried slashing that line in the original code to see what difference it makes. Or you can have it alert you what it is changing the display style to.
Re: SetInterval called function crashes
When I say it "crashes", it occurs when I debug it. If I run the page without debugging, there is no visible activity when I click start. When I debug it is when I discover it is crashing when the function exits.
Maybe I should just try stripping out all the AJAX extensions and see what happens. I don't know of any other way to put sliders on the page.
Re: SetInterval called function crashes
Slider as in custom scroll bar?