Order of execution

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • chirs

    #1

    Order of execution

    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=JavaSc ript>
    function listnum() {
    i=0
    do {
    document.write( i + "<br>")
    i++
    } while(i<10)
    }</SCRIPT>
    </HEAD>

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

    Thank you.
  • Vjekoslav Begovic

    #2
    Re: Order of execution

    "chirs" <yma@kicon.co m> wrote in message
    news:4c22a744.0 309151113.66551 a2@posting.goog le.com...[color=blue]
    > 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=JavaSc ript>
    > function listnum() {
    > i=0
    > do {
    > document.write( i + "<br>")
    > i++
    > } while(i<10)
    > }</SCRIPT>
    > </HEAD>
    >
    > <BODY onload=listnum( )>
    > hi
    > </BODY>[/color]

    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


    Comment

    • JB

      #3
      Re: Order of execution

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

      "Vjekoslav Begovic" <vjbegovic@inet .hr> wrote in message
      news:bk53os$jqm $1@sunce.iskon. hr...[color=blue]
      > "chirs" <yma@kicon.co m> wrote in message
      > news:4c22a744.0 309151113.66551 a2@posting.goog le.com...[color=green]
      > > 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=JavaSc ript>
      > > function listnum() {
      > > i=0
      > > do {
      > > document.write( i + "<br>")
      > > i++
      > > } while(i<10)
      > > }</SCRIPT>
      > > </HEAD>
      > >
      > > <BODY onload=listnum( )>
      > > hi
      > > </BODY>[/color]
      >
      > 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[/color]
      try[color=blue]
      > the following:
      >
      > <body>
      > <script type="text/javascript">
      > listnum();
      > </script>
      > hi
      > </body>
      >
      > HTH
      >
      > Vjekoslav
      >
      >[/color]


      Comment

      Working...