469,579 Members | 1,272 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

How can I interrupt code execution?

I write some JS code programmatically 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:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. initMyStuff();
  3. if(GetBacktoServer()) return;
  4. fillMyTable();
  5. 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:
Expand|Select|Wrap|Line Numbers
  1. if(!GetBacktoServer()) {
  2. fillMyTable();
  3. etc etc etc
  4. }
but as I'm generating the code programmatically 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?
Oct 25 '10 #1
1 2004
16,027 Expert Mod 8TB
Put the code inside a function. Then "return" will return from the function at that point.
Oct 27 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Jo | last post: by
1 post views Thread by Default | last post: by
5 posts views Thread by Adrian Enders | last post: by
1 post views Thread by Sabiyur | last post: by
reply views Thread by Kristijan Marin | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.