How can I interrupt code execution?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pmonte
    New Member
    • Jul 2009
    • 7

    How can I interrupt code execution?

    I write some JS code programmaticall y in code behind (.Net) and I need to stop the code to being executed at a certain point.
    In my HTML I have something like that:

    Code:
    <script type="text/javascript">
    initMyStuff();
    if(GetBacktoServer()) return;
    fillMyTable();
    etc etc etc
    In other words I need not to continue to fillMyTable() etc etc if GetBacktoServer () return true.
    I know this could be simply done with:
    Code:
    if(!GetBacktoServer()) {
    fillMyTable();
    etc etc etc
    }
    but as I'm generating the code programmaticall y this is quite hard to do for various reasons, so I need to use a return if true.
    The above works fine in Chrome but doesn't work in FireFox and IE. (firebug says return not in function)

    Any suggestions?
    Last edited by gits; Oct 27 '10, 01:09 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Put the code inside a function. Then "return" will return from the function at that point.

    Comment

    Working...