Order of execution

Discussion in 'Javascript' started by chirs, Sep 15, 2003.

  1. chirs

    chirs Guest

    I have a small code. It prints 0,1,...,9, but you cannot see the word
    "hi". It seems that it prints "hi" then executes the listnum
    function. But the listnum function is placed before "hi". Could you
    give me some info on order of execution?

    <HEAD>
    <SCRIPT language=JavaScript>
    function listnum() {
    i=0
    do {
    document.write( i + "<br>")
    i++
    } while(i<10)
    }</SCRIPT>
    </HEAD>

    <BODY onload=listnum()>
    hi
    </BODY>

    Thank you.
     
    chirs, Sep 15, 2003
    #1
    1. Advertising

  2. "chirs" <> wrote in message
    news:...
    > I have a small code. It prints 0,1,...,9, but you cannot see the word
    > "hi". It seems that it prints "hi" then executes the listnum
    > function. But the listnum function is placed before "hi". Could you
    > give me some info on order of execution?
    >
    > <HEAD>
    > <SCRIPT language=JavaScript>
    > function listnum() {
    > i=0
    > do {
    > document.write( i + "<br>")
    > i++
    > } while(i<10)
    > }</SCRIPT>
    > </HEAD>
    >
    > <BODY onload=listnum()>
    > hi
    > </BODY>


    The onLoad event handler triggers when a page finishes loading. When you
    document.write on such a page, you destroy the previous page. You could try
    the following:

    <body>
    <script type="text/javascript">
    listnum();
    </script>
    hi
    </body>

    HTH

    Vjekoslav
     
    Vjekoslav Begovic, Sep 15, 2003
    #2
    1. Advertising

  3. chirs

    JB Guest

    Try this,
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title></title>
    </HEAD>
    <BODY>
    Hi<br>
    <SCRIPT language=JavaScript>
    {
    i=0
    do {
    document.write( i + "<br>")
    i++
    } while(i<10)
    }</SCRIPT>
    </BODY>
    </html>
    ------------------------------------------------------

    "Vjekoslav Begovic" <> wrote in message
    news:bk53os$jqm$...
    > "chirs" <> wrote in message
    > news:...
    > > I have a small code. It prints 0,1,...,9, but you cannot see the word
    > > "hi". It seems that it prints "hi" then executes the listnum
    > > function. But the listnum function is placed before "hi". Could you
    > > give me some info on order of execution?
    > >
    > > <HEAD>
    > > <SCRIPT language=JavaScript>
    > > function listnum() {
    > > i=0
    > > do {
    > > document.write( i + "<br>")
    > > i++
    > > } while(i<10)
    > > }</SCRIPT>
    > > </HEAD>
    > >
    > > <BODY onload=listnum()>
    > > hi
    > > </BODY>

    >
    > The onLoad event handler triggers when a page finishes loading. When you
    > document.write on such a page, you destroy the previous page. You could

    try
    > the following:
    >
    > <body>
    > <script type="text/javascript">
    > listnum();
    > </script>
    > hi
    > </body>
    >
    > HTH
    >
    > Vjekoslav
    >
    >
     
    JB, Sep 18, 2003
    #3
    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. priya
    Replies:
    0
    Views:
    1,242
    priya
    Oct 3, 2005
  2. =?Utf-8?B?QmlsbCBCb3Jn?=

    Execution order of PageLoad for user controls

    =?Utf-8?B?QmlsbCBCb3Jn?=, Mar 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,369
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Mar 6, 2004
  3. Bijoy Naick

    Execution order of Validation Controls

    Bijoy Naick, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,970
    Martin Marinov
    Jun 8, 2004
  4. John Saunders

    Re: A question about order of execution?

    John Saunders, Jul 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    367
    S. Justin Gengo
    Jul 15, 2004
  5. S. Justin Gengo

    Re: A question about order of execution?

    S. Justin Gengo, Jul 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,063
    S. Justin Gengo
    Jul 15, 2004
Loading...

Share This Page