Showing a 'Waiting ...' Message

Discussion in 'Javascript' started by Mel Smith, Dec 13, 2011.

  1. Mel Smith

    Mel Smith Guest

    Hi:

    Because of some great help from Denis McMahon last March, I've been
    showing / sorting big tables with no problem

    The only problem I have is displaying a 'Waiting for Sort to Complete
    ....' message on the screen during the interval that sorting is taking place.

    The 'Wait' Message *does* display if I follow it with an Alert()
    message. Otherwise, it does *not* display.

    Is there some other way to *force* this following function to display ??

    // **** here is the 'wait' message function ****
    function showwaitmsg() {
    var el = document.getElementById("sorttext")
    el.style.color="white";
    el.style.background="red" ;
    el.value = " Sorting ... " ; // in IE7 and also Chrome, this doesn't
    display UNLESS you show an alert() message first
    return ;
    }
    // **** end of wait message function ****

    Thanks for any hints provided !

    --
    Mel Smith
    Mel Smith, Dec 13, 2011
    #1
    1. Advertising

  2. On Tue, 13 Dec 2011 10:26:34 -0700, "Mel Smith"
    <> wrote:

    > Because of some great help from Denis McMahon last March, I've been
    >showing / sorting big tables with no problem
    >
    > The only problem I have is displaying a 'Waiting for Sort to Complete
    >...' message on the screen during the interval that sorting is taking place.
    >
    > The 'Wait' Message *does* display if I follow it with an Alert()
    >message. Otherwise, it does *not* display.
    >
    > Is there some other way to *force* this following function to display ??


    You are not the only one to do battle with this. I am another. I
    found in my searching that many people had this problem. I do not
    have a for-sure answer, but for what it is worth...

    In my case, it was a tictactoe program. I was not always getting
    the display updated with the final plays before the win/lose alert()
    was displayed.

    >// **** here is the 'wait' message function ****
    >function showwaitmsg() {
    > var el = document.getElementById("sorttext")
    > el.style.color="white";
    > el.style.background="red" ;
    > el.value = " Sorting ... " ; // in IE7 and also Chrome, this doesn't
    >display UNLESS you show an alert() message first
    > return ;
    >}
    >// **** end of wait message function ****
    >
    > Thanks for any hints provided !


    In my case, I replaced the alert() with a setTimeout() to call
    another function (consisting of the alert() I wanted) with a timeout
    of 0 and then ended execution. It is important that execution end, or
    the function specified in the setTimeout() will not execute.

    I found that 0 worked just fine. I suspect that this allows the
    screen update thread an opportunity to run.

    In a related vein, I was trying to write something that would
    show an update such as
    1000 thingies somethingerised
    2000 thingies somethingerised
    3000 thingies somethingerised
    I got something that worked reliably, but unfortunately, I threw out
    my code. IIRC, my loop variable had to be global. I have tried to
    recreate the code, but the following does not quite work. The
    document.write() causes Looping() to become undefined! If I use an
    alert() instead (which rather defeats the purpose), it works.

    ***** Start of Semi-Working Code *****
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title>trytimeout.html</title>

    <script type="text/javascript">

    var i;

    function LoopStart()
    {
    alert("{LoopStart()");
    i=1;
    setTimeout("Looping()",0);
    }

    function Looping()
    {
    alert("{Looping @i="+i);
    DoSomething();
    if (i%3==0)
    document.writeln(i+" thingies somethingerised<br>"); //*****
    This causes trouble.
    i++;
    if (i<=10)
    {
    alert("@Looping() <setTimeout() @i="+i);
    setTimeout("Looping()",0);
    alert("@Looping() >setTimeout() @i="+i);
    }
    }

    function DoSomething()
    {
    for (var i=1; i<=1000; i++)
    ;
    }

    </script>

    </head>

    <body>

    <script type="text/javascript">
    LoopStart();
    </script>

    </body>

    </html>
    ***** End of Semi-Working Code *****


    The above is a semi-educated guess, and I would welcome
    correction if there is a reliable, cross-platform way to do it.

    Sincerely,

    Gene Wirchenko
    2
    Gene Wirchenko, Dec 13, 2011
    #2
    1. Advertising

  3. Mel Smith

    Mel Smith Guest

    Gene:

    Thanks for the code. I'll work on trying to implement it and let you
    know.

    -Mel Smith
    Mel Smith, Dec 13, 2011
    #3
  4. On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
    <> wrote:

    > Thanks for the code. I'll work on trying to implement it and let you
    >know.


    I am going to take another whack at it. I had it working.
    HONEST! REALLY! I thought I had the issue dealt with and so could
    toss the code.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 14, 2011
    #4
  5. On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <>
    wrote:

    >On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
    ><> wrote:
    >
    >> Thanks for the code. I'll work on trying to implement it and let you
    >>know.

    >
    > I am going to take another whack at it. I had it working.
    >HONEST! REALLY! I thought I had the issue dealt with and so could
    >toss the code.


    I think I originally had it working with console.log(). I got
    the to work when I changed the document.writeln() to console.log().

    Does anyone know why the document.writeln() causes Looping() to
    become undefined?

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 14, 2011
    #5
  6. On Dec 14, 2:10 am, Gene Wirchenko <> wrote:
    > On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <>
    > wrote:
    >
    > >On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
    > ><> wrote:

    >
    > >>    Thanks for the code.  I'll work on trying to implement it andlet you
    > >>know.

    >
    > >     I am going to take another whack at it.  I had it working.
    > >HONEST!  REALLY!  I thought I had the issue dealt with and so could
    > >toss the code.

    >
    >      I think I originally had it working with console.log().  I got
    > the to work when I changed the document.writeln() to console.log().
    >
    >      Does anyone know why the document.writeln() causes Looping() to
    > become undefined?
    >
    > Sincerely,
    >
    > Gene Wirchenko


    http://www.google.co.uk/search?q=ja...s=org.mozilla:en-GB:official&client=firefox-a

    Typically any use of document.write() after the page has loaded will
    replace the entire page content.

    So your javascript is wiped out and Looping() is undefined.

    Martin.
    Martin Pearman, Dec 14, 2011
    #6
  7. On Tue, 13 Dec 2011 23:07:21 -0800 (PST), Martin Pearman
    <> wrote:

    >On Dec 14, 2:10 am, Gene Wirchenko <> wrote:
    >> On Tue, 13 Dec 2011 17:50:10 -0800, Gene Wirchenko <>
    >> wrote:
    >>
    >> >On Tue, 13 Dec 2011 15:31:41 -0700, "Mel Smith"
    >> ><> wrote:

    >>
    >> >>    Thanks for the code.  I'll work on trying to implement it and let you
    >> >>know.

    >>
    >> >     I am going to take another whack at it.  I had it working.
    >> >HONEST!  REALLY!  I thought I had the issue dealt with and so could
    >> >toss the code.

    >>
    >>      I think I originally had it working with console.log().  I got
    >> the to work when I changed the document.writeln() to console.log().
    >>
    >>      Does anyone know why the document.writeln() causes Looping() to
    >> become undefined?


    >http://www.google.co.uk/search?q=ja...s=org.mozilla:en-GB:official&client=firefox-a
    >
    >Typically any use of document.write() after the page has loaded will
    >replace the entire page content.
    >
    >So your javascript is wiped out and Looping() is undefined.


    I have a number of pages that do have document.write() calls in
    them, and they work fine. The pages are presumably loaded at the time
    the document.write() calls are made as some of those are in the body.
    In one page, the body consists only of JavaScript code: a variable
    creation and four document.write() calls using the variable and a
    method defined in the head.

    Could you please clarify your response?

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 14, 2011
    #7
  8. In comp.lang.javascript message <>, Tue,
    13 Dec 2011 10:26:34, Mel Smith <> posted:

    >
    > The only problem I have is displaying a 'Waiting for Sort to Complete
    >...' message on the screen during the interval that sorting is taking place.


    Display the message as the last thing but one that gets executed. The
    last thing is a setTimeout that calls the sort routine after some short
    interval, say 100 ms. At the end of the sort, remove or alter the wait
    message.

    --
    (c) John Stockton, nr London, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
    Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

    Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>
    Dr J R Stockton, Dec 14, 2011
    #8
  9. On Wed, 14 Dec 2011 21:18:21 +0100, Jake Jarvis
    <> wrote:

    >On 14.12.2011 19:46, Gene Wirchenko wrote:
    ><snip>
    >>
    >> I have a number of pages that do have document.write() calls in
    >> them, and they work fine. The pages are presumably loaded at the time
    >> the document.write() calls are made as some of those are in the body.
    >> In one page, the body consists only of JavaScript code: a variable
    >> creation and four document.write() calls using the variable and a
    >> method defined in the head.
    >>
    >> Could you please clarify your response?
    >>

    >
    >In effect you are "overwriting" the old document with a new one, what
    >happens with the "script environment" associated with the old document
    >is anyone's guess, chrome for example guesses it should be kept around,
    >firefox doesn't.
    >
    >But document.write doesn't always mean "overwrite", it can also mean
    >"insert" into what the browser is currently reading and from which it'll
    >build a document.


    So how do I tell that the page has been loaded or that it is not
    yet? That page with a JavaScript-only body ends scant bytes after,
    and its document.write() calls do not clear the page.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 14, 2011
    #9
  10. Mel Smith

    Evertjan. Guest

    Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:

    > So how do I tell that the page has been loaded or that it is not
    > yet? That page with a JavaScript-only body ends scant bytes after,
    > and its document.write() calls do not clear the page.


    A page is loaded when all html and direct script is executed and before
    body.onload starts executing.

    All code that starts after that point and contains ..

    document.write()

    ... executes an implicit ''

    document.open()

    ... first,
    thereby destroying the loaded document and starting a new document.

    Such code starts by an event-listener, like:
    onload='myfunction()';
    onfocus='myfunction()';
    onclick='myfunction()';
    setTimeout('myfunction()',milisecs);
    etc.

    In short, you cannot document.write() into[!!] a page/document
    that is ready [="loaded"].

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Dec 14, 2011
    #10
  11. Mel Smith

    Mel Smith Guest

    Dr. Stockton said:
    > Display the message as the last thing but one that gets executed. The
    > last thing is a setTimeout that calls the sort routine after some short
    > interval, say 100 ms. At the end of the sort, remove or alter the wait
    > message.
    >


    Dr Stockton:

    Thank you for the suggestion above. I'll go back to work on it
    tomorrow.

    ( Been golfing/partying lately :)) )

    -Mel
    Mel Smith, Dec 14, 2011
    #11
  12. On 14 Dec 2011 22:56:11 GMT, "Evertjan."
    <> wrote:

    >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
    >
    >> So how do I tell that the page has been loaded or that it is not
    >> yet? That page with a JavaScript-only body ends scant bytes after,
    >> and its document.write() calls do not clear the page.

    >
    >A page is loaded when all html and direct script is executed and before
    >body.onload starts executing.


    This still is not clear. What is direct script?

    I have code that works fine and has document.write() calls in the
    body. Other code blows up.

    At what point does JavaScript get executed?

    Nothing I have read (including the standard) covers this at all
    or very well. I have been unable to find any explanation such that,
    suing it, I could then look at some code and determine whether it
    would wipe out my page or not.

    If you have a URL, I will happily read that.

    [snip]

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 15, 2011
    #12
  13. In article <>,
    Gene Wirchenko <> wrote:
    > On 14 Dec 2011 22:56:11 GMT, "Evertjan."
    > <> wrote:
    >
    > >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
    > >
    > >> So how do I tell that the page has been loaded or that it is not
    > >> yet? That page with a JavaScript-only body ends scant bytes after,
    > >> and its document.write() calls do not clear the page.

    > >
    > >A page is loaded when all html and direct script is executed and before
    > >body.onload starts executing.

    >
    > This still is not clear. What is direct script?


    Code that is executed at the time the page is being built, e.g.

    <body>
    <h1>Test page</h1>
    <p>This comes before the hello world.</p>
    <script type="text/javascript">
    document.write("<p>Hello, world!</p>\n");
    setTimeout(function() {document.write("Completely new page\n");}, 5000);
    </script>
    <p>This comes after the hello world.</p>
    </body>

    > I have code that works fine and has document.write() calls in the
    > body.


    As above, yes.

    > Other code blows up.


    If it gets invoked after the page has finished, by being called by an event
    or a timeout.

    > At what point does JavaScript get executed?


    As it gets encountered. But for any code executed from an event, after the page
    has loaded, the document.write calls will replace the page.
    In the above example, the function within setTimeout() gets defined as
    the page is built, but EXECUTED later.

    > Nothing I have read (including the standard) covers this at all
    > or very well. I have been unable to find any explanation such that,
    > suing it, I could then look at some code and determine whether it
    > would wipe out my page or not.
    >
    > If you have a URL, I will happily read that.


    If you want to update parts of your page after it has loaded, then you
    don't want document.write(). Instead, you have to manipulate the DOM, by
    having empty divs with ids in your document, and then at run time get a
    reference to them and either write to their innerHTML property, or attach
    new DOM elements to them.

    Hope this helps!

    Tony
    --
    Tony Mountifield
    Work: - http://www.softins.co.uk
    Play: - http://tony.mountifield.org
    Tony Mountifield, Dec 15, 2011
    #13
  14. Mel Smith

    Evertjan. Guest

    Gene Wirchenko wrote on 15 dec 2011 in comp.lang.javascript:

    >>> So how do I tell that the page has been loaded or that it is not
    >>> yet? That page with a JavaScript-only body ends scant bytes after,
    >>> and its document.write() calls do not clear the page.

    >>
    >>A page is loaded when all html and direct script is executed and before
    >>body.onload starts executing.

    >
    > This still is not clear. What is direct script?


    Direct/immediate script execution
    = execution before the page is fully loaded.

    "loaded" means built. Listener "onload" should have been called "onloaded".

    Perhaps some experimenting experience will do better than explaining.

    You are skipping what I wrote about code that is only executed by
    a trigger from a event-listener or timeout execution. And that is just the
    crux.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Dec 15, 2011
    #14
  15. On Thu, 15 Dec 2011 08:40:54 +0000 (UTC), (Tony
    Mountifield) wrote:

    >In article <>,
    >Gene Wirchenko <> wrote:
    >> On 14 Dec 2011 22:56:11 GMT, "Evertjan."
    >> <> wrote:
    >>
    >> >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
    >> >
    >> >> So how do I tell that the page has been loaded or that it is not
    >> >> yet? That page with a JavaScript-only body ends scant bytes after,
    >> >> and its document.write() calls do not clear the page.
    >> >
    >> >A page is loaded when all html and direct script is executed and before
    >> >body.onload starts executing.

    >>
    >> This still is not clear. What is direct script?

    >
    >Code that is executed at the time the page is being built, e.g.
    >
    ><body>
    ><h1>Test page</h1>
    ><p>This comes before the hello world.</p>
    ><script type="text/javascript">
    >document.write("<p>Hello, world!</p>\n");
    >setTimeout(function() {document.write("Completely new page\n");}, 5000);
    ></script>
    ><p>This comes after the hello world.</p>
    ></body>
    >
    >> I have code that works fine and has document.write() calls in the
    >> body.

    >
    >As above, yes.
    >
    >> Other code blows up.

    >
    >If it gets invoked after the page has finished, by being called by an event
    >or a timeout.


    But it is not. It gets invoked in the body. Here is the code
    again:

    ***** Start of Semi-Working Code *****
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title>trytimeout.html</title>

    <script type="text/javascript">

    var i;

    function LoopStart()
    {
    alert("{LoopStart()");
    i=1;
    setTimeout("Looping()",0);
    }

    function Looping()
    {
    alert("{Looping @i="+i);
    DoSomething();
    if (i%3==0)
    document.writeln(i+" thingies somethingerised<br>"); //*****
    This causes trouble.
    i++;
    if (i<=10)
    {
    alert("@Looping() <setTimeout() @i="+i);
    setTimeout("Looping()",0);
    alert("@Looping() >setTimeout() @i="+i);
    }
    }

    function DoSomething()
    {
    for (var i=1; i<=1000; i++)
    ;
    }

    </script>

    </head>

    <body>

    <script type="text/javascript">
    LoopStart();
    </script>

    </body>

    </html>
    ***** End of Semi-Working Code *****

    So why does the loop not work? IIUC, the LoopStart() call is
    executed as it is encountered, and the loop should work. It blows up.

    >> At what point does JavaScript get executed?

    >
    >As it gets encountered. But for any code executed from an event, after the page
    >has loaded, the document.write calls will replace the page.
    >In the above example, the function within setTimeout() gets defined as
    >the page is built, but EXECUTED later.


    While the page is still getting set up. So why is it then lost?

    >> Nothing I have read (including the standard) covers this at all
    >> or very well. I have been unable to find any explanation such that,
    >> suing it, I could then look at some code and determine whether it
    >> would wipe out my page or not.
    >>
    >> If you have a URL, I will happily read that.

    >
    >If you want to update parts of your page after it has loaded, then you
    >don't want document.write(). Instead, you have to manipulate the DOM, by
    >having empty divs with ids in your document, and then at run time get a
    >reference to them and either write to their innerHTML property, or attach
    >new DOM elements to them.


    I thought that I was generating my page.

    >Hope this helps!


    Nope.

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 15, 2011
    #15
  16. In article <>,
    Gene Wirchenko <> wrote:
    > On Thu, 15 Dec 2011 08:40:54 +0000 (UTC), (Tony
    > Mountifield) wrote:
    >
    > >In article <>,
    > >Gene Wirchenko <> wrote:
    > >> On 14 Dec 2011 22:56:11 GMT, "Evertjan."
    > >> <> wrote:
    > >>
    > >> >Gene Wirchenko wrote on 14 dec 2011 in comp.lang.javascript:
    > >> >
    > >> >> So how do I tell that the page has been loaded or that it is not
    > >> >> yet? That page with a JavaScript-only body ends scant bytes after,
    > >> >> and its document.write() calls do not clear the page.
    > >> >
    > >> >A page is loaded when all html and direct script is executed and before
    > >> >body.onload starts executing.
    > >>
    > >> This still is not clear. What is direct script?

    > >
    > >Code that is executed at the time the page is being built, e.g.
    > >
    > ><body>
    > ><h1>Test page</h1>
    > ><p>This comes before the hello world.</p>
    > ><script type="text/javascript">
    > >document.write("<p>Hello, world!</p>\n");
    > >setTimeout(function() {document.write("Completely new page\n");}, 5000);
    > ></script>
    > ><p>This comes after the hello world.</p>
    > ></body>
    > >
    > >> I have code that works fine and has document.write() calls in the
    > >> body.

    > >
    > >As above, yes.
    > >
    > >> Other code blows up.

    > >
    > >If it gets invoked after the page has finished, by being called by an event
    > >or a timeout.

    >
    > But it is not. It gets invoked in the body. Here is the code
    > again:
    >
    > ***** Start of Semi-Working Code *****
    > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    > <html xmlns="http://www.w3.org/1999/xhtml">
    >
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1" />
    > <title>trytimeout.html</title>
    >
    > <script type="text/javascript">
    >
    > var i;
    >
    > function LoopStart()
    > {
    > alert("{LoopStart()");
    > i=1;
    > setTimeout("Looping()",0);
    > }
    >
    > function Looping()
    > {
    > alert("{Looping @i="+i);
    > DoSomething();
    > if (i%3==0)
    > document.writeln(i+" thingies somethingerised<br>"); //*****
    > This causes trouble.
    > i++;
    > if (i<=10)
    > {
    > alert("@Looping() <setTimeout() @i="+i);
    > setTimeout("Looping()",0);
    > alert("@Looping() >setTimeout() @i="+i);
    > }
    > }
    >
    > function DoSomething()
    > {
    > for (var i=1; i<=1000; i++)
    > ;
    > }
    >
    > </script>
    >
    > </head>
    >
    > <body>
    >
    > <script type="text/javascript">
    > LoopStart();
    > </script>
    >
    > </body>
    >
    > </html>
    > ***** End of Semi-Working Code *****
    >
    > So why does the loop not work? IIUC, the LoopStart() call is
    > executed as it is encountered, and the loop should work. It blows up.


    The functions get defined in the HEAD before the page is rendered.
    OK so far.

    The call to LoopStart() happens while the page is being built.
    LoopStart() executes at that time. If LoopStart() contained a
    document.write(), the output of that would appear within the page.

    One of the things that LoopStart() does is to queue a call to Looping()
    to be executed at some time in the future, but at least 0ms later.
    A setTimeout() with timeout of zero does NOT execute the function
    argument there and then.

    LoopStart() returns and the page finishes rendering.

    Once the page has *finished rendering*, the queued call to Looping()
    is then executed. It includes a document.write() which replaces the
    displayed page that had already been completed.

    The rule is not to use document.write() in ANY function that is
    reached via a setTimeout(), setInterval() or an onxxxx event handler.
    Only in code that is actually executed (not just defined) while the
    page is being built.

    Hope this is clearer!

    Tony
    --
    Tony Mountifield
    Work: - http://www.softins.co.uk
    Play: - http://tony.mountifield.org
    Tony Mountifield, Dec 15, 2011
    #16
  17. In comp.lang.javascript message <-berlin.de>, Wed,
    14 Dec 2011 21:18:21, Jake Jarvis <> posted:

    >On 14.12.2011 19:46, Gene Wirchenko wrote:
    ><snip>
    >>
    >> I have a number of pages that do have document.write() calls in
    >> them, and they work fine. The pages are presumably loaded at the time
    >> the document.write() calls are made as some of those are in the body.
    >> In one page, the body consists only of JavaScript code: a variable
    >> creation and four document.write() calls using the variable and a
    >> method defined in the head.
    >>
    >> Could you please clarify your response?
    >>

    >
    >In effect you are "overwriting" the old document with a new one, what
    >happens with the "script environment" associated with the old document
    >is anyone's guess, chrome for example guesses it should be kept around,
    >firefox doesn't.
    >
    >But document.write doesn't always mean "overwrite", it can also mean
    >"insert" into what the browser is currently reading and from which
    >it'll build a document.



    It never inserts. It appends to as much of the DOM representation has
    already been constructed, and that which is constructed later follows
    it.

    --
    (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
    Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
    Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
    No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
    Dr J R Stockton, Dec 15, 2011
    #17
  18. Mel Smith

    Mel Smith Guest

    Dr John Stockton and Gene Wirchenko:

    Following the instructions of Dr. John, I build this little 'looperr'
    below that shows my warning message finally :((

    Hope this helps others.

    -Mel Smith


    *************************

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
    <title>loopmsg.htm</title>

    <script type="text/javascript">

    var nCrud = 0

    function LooperSorter() {

    var el = document.getElementById("looptotal") ;
    el.value = nCrud.toString() ; // clear out the total field

    var mypi = 3.1415926 ;

    // You may wish to make a significantly more complex loop so that
    // the 'Looping' Message can be seen easier

    for (var i=0; i <= 3000000; i++) {
    nCrud = (i / mypi) + 1234.567;
    }

    // Now at end of Loop, So, prove it by placing the
    // nCrud vrbl total in the looptotal field
    var el = document.getElementById("looptotal") ;
    el.value = nCrud.toString() ;

    // Now, Restore the original message
    var el = document.getElementById("looptext") ;
    el.style.color = "yellow" ;
    el.style.background = "gray" ;
    el.value = "Ready to Loop"
    }

    function showwaitmsg() {
    var el = document.getElementById("looptext") ;
    el.style.color="white";
    el.style.background="red" ;
    el.value = " Looping ... " ;
    return ;
    }

    function startloop() {

    // First, show the 'Looping ... ' Message
    showwaitmsg() ; // shows the message White on Red background

    // Then, wait 1/20th of a second to give the 'wait' message
    // some time to display.
    // At the end of the 'LooperSorter' Code, the original message
    // is restored to the message field.

    // You may also wish to set the delay to 0 millisecs to test it.
    setTimeout("LooperSorter()",200) ; // wait .20 secs, then restore message

    // You cannot place the message restoration code *here* because the
    // message will be restored *before* the 'looper' even runs !
    }
    </script>

    </head>

    <body>
    <form action="#" >
    &nbsp;&nbsp;Click to Loop : <input type="button" onclick="startloop();"
    value="Start Timer" />
    &nbsp;&nbsp;Loop Total : <input type="text" id="looptotal" value="0" />
    <br />
    <br />
    &nbsp;Loop Message&nbsp;:&nbsp;<input type="text" readonly="readonly"
    id="looptext"
    style="width:12em;font-weight:bold;color:yellow;background:gray;text-align:center;" value="Ready to Loop" /></form></body></html>
    Mel Smith, Dec 15, 2011
    #18
  19. On Thu, 15 Dec 2011 20:36:33 +0000 (UTC), (Tony
    Mountifield) wrote:

    [snip]

    >> So why does the loop not work? IIUC, the LoopStart() call is
    >> executed as it is encountered, and the loop should work. It blows up.

    >
    >The functions get defined in the HEAD before the page is rendered.
    >OK so far.
    >
    >The call to LoopStart() happens while the page is being built.
    >LoopStart() executes at that time. If LoopStart() contained a
    >document.write(), the output of that would appear within the page.


    Confirmed.

    >One of the things that LoopStart() does is to queue a call to Looping()
    >to be executed at some time in the future, but at least 0ms later.
    >A setTimeout() with timeout of zero does NOT execute the function
    >argument there and then.
    >
    >LoopStart() returns and the page finishes rendering.
    >
    >Once the page has *finished rendering*, the queued call to Looping()
    >is then executed. It includes a document.write() which replaces the
    >displayed page that had already been completed.


    Got it.

    >The rule is not to use document.write() in ANY function that is
    >reached via a setTimeout(), setInterval() or an onxxxx event handler.
    >Only in code that is actually executed (not just defined) while the
    >page is being built.
    >
    >Hope this is clearer!


    Yup! That did it. Thank you very much.

    Now, why do I not find this sort of stuff written up in any books
    or Website that I read? I only find out because of running into the
    problems. Not the most efficient way of going about things, is it?

    Sincerely,

    Gene Wirchenko
    Gene Wirchenko, Dec 15, 2011
    #19
  20. Mel Smith

    Scott Sauyet Guest

    Gene Wirchenko wrote:
    >      Yup!  That did it.  Thank you very much.
    >
    >      Now, why do I not find this sort of stuff written up in any books
    > or Website that I read?  I only find out because of running into the
    > problems.  Not the most efficient way of going about things, is it?


    It's not clear to me why, but the overall quality of Javascript books
    seems significantly lower than the quality on many other programming
    topics. For a long time I would only recommend Flanagan's,
    _Javascript: The Definitive Guide_ and (with some significant
    caveats), Crockford's _Javascript: The Good Parts_. These days, I'd
    also include, again with caveats, Stefanov's _Javascript Pattern_ and
    Zakas' _High Performance Javascript_. I've heard really good things
    about Haverbeke _Eloquent Javascript_ as a beginner's book, but I
    haven't really been through it.

    As to websites, there is plenty of good stuff out there. But there is
    much, much more that is pure nonsense, or, worse, only pseudo-
    sensible. Anyone who has made something `work` on a webpage with JS
    seems to think that immediately qualifies them as an expert, and they
    publish much rubbish.

    The best way to learn this stuff is to continually experiment, post in
    groups like this one and jsmentors, read one or two of the books
    above, and most of all, just keep trying. If you want other online
    resources, the `blogs` section of Rey Bango's post lists many good
    resources: <http://blog.reybango.com/2010/12/15/what-to-read-to-get-
    up-to-speed-in-javascript/>

    Good luck,

    -- Scott
    Scott Sauyet, Dec 16, 2011
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grant Merwitz

    XmlHttp (Ajax) Show Waiting Message

    Grant Merwitz, Jan 10, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    7,834
    Grant Merwitz
    Jan 11, 2006
  2. kastis

    waiting message

    kastis, Dec 14, 2003, in forum: Java
    Replies:
    4
    Views:
    628
    Raymond DeCampo
    Dec 20, 2003
  3. Mark Richards
    Replies:
    2
    Views:
    1,101
    Andrew Thompson
    Oct 8, 2004
  4. =?Utf-8?B?SGlyYWs=?=
    Replies:
    0
    Views:
    1,322
    =?Utf-8?B?SGlyYWs=?=
    May 26, 2006
  5. Replies:
    0
    Views:
    527
Loading...

Share This Page