app79 common wisdom, helpful code and useful apps

11Aug/090

IE Stack Overflow Javascript Fix

Fix for calling the same function a few times in an almost infinite loop using the onchange event and getting a stack overflow at line 0 or any other line error in Internet Explorer:

function MyFunction(currentTextBox, nextTextBox)

{

//magic code in here

//when magic finished, call next magic spell

setTimeout(function(){FireNextBox(nextTextBox},1);

}

function FireNextBox(nextTextBox)

{

nextTextBox.onchange();

}

//for last textbox in loop

function FinalFunction()

{

return;

//the end

}

The above scenario assumes the onchange event calls ‘MyFunction’ and there is a return function available, ‘FinalFunction’ that is called by the onchange event of the last textbox in this loop. Using setTimeout is necessary in Internet Explorer, otherwise it will throw a stack overflow error, works fine in Firefox with and without the setTimeout.

share:
  • Facebook
  • TwitThis
  • MySpace
  • Digg
  • del.icio.us
  • Google
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

Recent Posts

Archives

Blogroll

Categories

Tags

cartoon corporate email first funny how to internet internet explorer javascript linux computers os management office marshmallow theory onchange sadness singularity no theory robot stack overflow tech support tutorial upside down computer video youtube