"onload" method

J

JS

I have two functions in an external .js page:

createMenu(sel){
document.write("TEST1");
}

createFirstMenu(sel){
document.write("TEST2");
}


I have another page that includes this javaScript. In this page I use <body
onload="createMenu('sel1');">:

<body onload="createMenu('sel1')">
<form name="sels" method="post" action="?page=jubii">
Kategori:&nbsp;&nbsp;&nbsp;
<select name="sel1" id="sel1" onchange="createMenu('sel1','sel2');">
</select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
-er- Vælg --</option>
</select>
&nbsp;
<input name="search" type="text" id="search">
&nbsp;
<input type="submit" name="Submit" value="Søg">
</form>

"TEST1" get printed when I open this page as expected.

But if I change onload to:
<body onload="createFirstMenu('sel1')">

I don't get "TEST2" printed!


What are the explanation?
 
J

JS

JS said:
I have two functions in an external .js page:

createMenu(sel){
document.write("TEST1");
}

createFirstMenu(sel){
document.write("TEST2");
}


I tried to switch the order of the two methods:

createFirstMenu(sel){
document.write("TEST2");
}

createMenu(sel){
document.write("TEST1");
}

And now it works! But I don't know why....is it nessecary to write methods
in a strict order?
 
D

Daniel Kirsch

JS said:
createFirstMenu(sel){
document.write("TEST2");
}

createMenu(sel){
document.write("TEST1");
}

And now it works! But I don't know why....is it nessecary to write methods
in a strict order?

No. Your give example works for me (if I add the word "function" before
each function).

You may give us an URL with an example so we may take a look.

Daniel
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,084
Latest member
HansGeorgi

Latest Threads

Top