Zakalwe
01-28-2009, 01:45 PM
Hi everyone,
I am having issues with the following bit of code:
function test(){
window.alert("Alert1");
var testvar = document.getElementById("topMenu").getElementsByTagName("li");
window.alert("Alert2");
}
if (window.attachEvent) window.attachEvent("onload", test());
When the page loads "Alert1" is being displayed however "Alert2" is not.
If I call the function from within the page itself (example below) both "Alert1" and "Alert2" are being displayed.
// It works this way!
<script type="text/javascript">
test();
</script>
I have a funny feeling that this problem stems from my limited knowledge of Javascript (I'm bound to be doing something wrong!), any help or advice that you can give would be much appreciated.
Cheers,
Chris
I am having issues with the following bit of code:
function test(){
window.alert("Alert1");
var testvar = document.getElementById("topMenu").getElementsByTagName("li");
window.alert("Alert2");
}
if (window.attachEvent) window.attachEvent("onload", test());
When the page loads "Alert1" is being displayed however "Alert2" is not.
If I call the function from within the page itself (example below) both "Alert1" and "Alert2" are being displayed.
// It works this way!
<script type="text/javascript">
test();
</script>
I have a funny feeling that this problem stems from my limited knowledge of Javascript (I'm bound to be doing something wrong!), any help or advice that you can give would be much appreciated.
Cheers,
Chris