Drop-Down Script Interfering with Loader Script

Hi again,

I have another little problem with a javascript maybe someone could help me with.

I have this loader script in the head of my page:


<script type="text/javascript">
function preloader(){
document.getElementById("loading").style.display = "none";}
window.onload = preloader;
</script>

Works perfect.

Lately I’ve added a Question & Answer page with drop-down script here:


<script type="text/javascript">
 var ids=new Array();

function QAinit(){
if(document.getElementById){
var tids=document.getElementsByTagName('div');
for(i=0;i<tids.length;i++)if(tids[i].className=="question")ids[ids.length]=tids[i];
for(i=0;i<ids.length;i++)ids[i].onmouseup=setstate;
}}

function setstate(){
for(i=0;i<ids.length;i++){
if(ids[i]==this){
var d=this.parentNode.getElementsByTagName('div')[1];
if(d.style.display=="block")d.style.display="none";
else d.style.display="block";
}}}

function expandall(){
if(document.getElementById){
for(i=0;i<ids.length;i++)ids[i].parentNode.getElementsByTagName('div')[1].style.display="block";
}}

function collapseall(){
if(document.getElementById){
for(i=0;i<ids.length;i++)ids[i].parentNode.getElementsByTagName('div')[1].style.display="none";
}}

window.onload=QAinit;</script>

This works perfect too.

But now on this new Q&A page the loader image never stops. It just keeps saying the page is loading when it’s not. It looks to me like they are somehow interfering with each other but I’m not sure how.

Hi,
What’s the address of the page where I can view the problem?

The preloader function is never being called because window.onload is being overwitten by the other script.

Quick fix:


window.onload = function(e) {
     preloader();
     QAinit();
};

Than remove these lines:

window.onload=QAinit;
window.onload = preloader;

I’m currently working on the site on my localhost using Wamp.

Thanks, this worked. :slight_smile: