SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    PHP Code:
    <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:

    PHP Code:
    <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.

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,051
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi,
    What's the address of the page where I can view the problem?

  3. #3
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pullo View Post
    Hi,
    What's the address of the page where I can view the problem?
    I'm currently working on the site on my localhost using Wamp.

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,192
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    The preloader function is never being called because window.onload is being overwitten by the other script.

    Quick fix:
    Code JavaScript:
    window.onload = function(e) {
         preloader();
         QAinit();
    };

    Than remove these lines:

    window.onload=QAinit;
    window.onload = preloader;
    The only code I hate more than my own is everyone else's.

  5. #5
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by oddz View Post
    The preloader function is never being called because window.onload is being overwitten by the other script.

    Quick fix:
    Code JavaScript:
    window.onload = function(e) {
         preloader();
         QAinit();
    };

    Than remove these lines:

    window.onload=QAinit;
    window.onload = preloader;
    Thanks, this worked.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •