By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,700 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

Order of execution

P: n/a
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.
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"chirs" <ym*@kicon.com> wrote in message
news:4c*************************@posting.google.co m...
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
Jul 20 '05 #2

P: n/a
JB
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" <vj*******@inet.hr> wrote in message
news:bk**********@sunce.iskon.hr...
"chirs" <ym*@kicon.com> wrote in message
news:4c*************************@posting.google.co m...
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

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.