Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with IE debug error

Options
  • 07-05-2010 9:20am
    #1
    Registered Users Posts: 1,459 ✭✭✭


    Hi there, i am working on a bit of code here and getting the following error (see attachment) trough IE... however in chrome and firefox all is ok. but i would like to find out whats causing it..

    the attachment also shows the code and line 54 that the error refers to..

    any help would be greatly accepted.. im no pro when it comes to Javascript, and will crack up if its just a case of a missing comma or bracket or something haha

    cheers
    H


Comments

  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Can you post the JavaScript inbetween [code] tags, and also the relevant section of HTML? It's hard to diagnose a problem from an image with script that isn't indented.


  • Registered Users Posts: 1,459 ✭✭✭Heathen


    Opps sorry ;-)

    here is the JavaScript, i have the offending line in BOLD

    <script type="text/javascript">
    
    /* NOT CURRENTLY USED
    var thedate = new Date();
    var dayofweek = thedate.getDay();
    var hourofday = thedate.getHours();
    
    var GMT = new Date().getTimezoneOffset();
    var offsetGMT = -5 * new Date().getTimezoneOffset()/60;
    */
    
    // Sun=0 1 2 3 4 5 Sat=6
    var DayOfWeek = new Array('Weekend','Monday','Tuesday','Wednesday','Thursday','Friday','Weekend');
    
    var NoShow = 'No Show Scheduled<br />for KSWH';
    var DH = new Array (7);
    for (d=0; d<7; d++) {
    DH[d] = new Array (24);
    for (h=0; h<24; h++) { DH[d][h] = ''; }
    }
    
    DH[1][10] = 'Monday at 10 AM<br>Modern Rock<br>with Cody Graves';
    DH[1][12] = 'No Show Name<br>with DJ JT<br>Monday at Noon<br>No Genre';
    DH[1][14] = 'Real Talk<br>with DJ Yella<br>Monday at 2 PM<br>No Genre';
    DH[1][16] = 'No Show Name<br>with Katy Cox<br>Monday at 4 PM<br>Rap';
    DH[1][17] = 'The Greatest<br>with DJ Fresh<br>Monday at 5 PM<br>No Genre';
    DH[1][18] = 'Revolution Corner<br>with Randy Underwood<br>Monday at 6 PM<br>No Genre';
    DH[1][20] = 'Daily Affirmation<br>with DJ Hightower<br>Monday at 8 PM<br>No Genre';
    DH[1][22] = 'No Show Name<br>with David Doggett<br>Monday 10 to Midnight<br>No Genre';
    DH[1][23] = 'No Show Name<br>with David Doggett<br>Monday at 11 PM<br>No Genre';
    DH[2][13] = 'No Show Name<br>with Michelle Caillouet<br>Tuesday at 1 PM<br>Rock';
    DH[2][16] = 'No Show Name<br>with Sweet Action Jackson<br>Tuesday at 4 PM<br>Rock';
    DH[2][20] = 'The Rock Hour<br>with Dan the Man<br>Tuesday at 8 PM<br>No Genre';
    DH[3][10] = 'Love Me! Hate Me!<br>with DJ Nia<br>Wednesday at 10 AM<br>No Genre';
    DH[3][11] = 'Westcoast Wednesdays<br>with DJ Smoove<br>Wednesday at 11 AM<br>No Genre';
    DH[3][15] = 'The Storm Hour<br>with the Weatherman and Reba<br>Wednesday 3 to 5 PM<br>Classic Rock';
    DH[3][16] = 'The Storm Hour<br>with the Weatherman and Reba<br>Wednesday at 4 PM<br>Classic Rock';
    DH[3][22] = 'EZ Does It<br>with DJ EZ<br>Wednesday at 10 PM<br>Rap';
    DH[4][12] = 'The Quad Show<br>with J Bean & LongJohn<br>Thursday Noon to 2 PM<br>Rap/Urban';
    DH[4][13] = 'The Quad Show<br>with J Bean & LongJohn<br>Thursday at 1 PM<br>Rap/Urban';
    DH[4][14] = 'The Hour<br>with DJ V-Jeezy<br>Thursday at 2 PM<br>No Genre';
    DH[4][15] = 'No Show Name<br>with DJ Savana<br>Thursday at 3 PM<br>No Genre';
    DH[5][10] = 'Friday at 10 AM<br>Christian Music<br>with Jammin J';
    DH[5][11] = 'Friday at 11 AM<br>Christian Music<br>with Jammin J';
    DH[5][12] = 'Friday at Noon<br>Modern Rock<br>with Tag and Em';
    DH[5][13] = 'Friday at 1 PM<br>Modern Rock<br>with Tag and Em';
    DH[5][14] = 'Friday at 2 PM<br>Urban Music<br>with Brandon Tabor';
    DH[5][15] = 'Friday at 3 PM<br>Unknown Genre<br>with DJ Kevin';
    DH[5][16] = 'Friday at 4 PM<br>Urban Music<br>with Big Hampton';
    DH[5][17] = 'Friday at 5 PM<br>Urban Music<br>with Big Hampton';
    DH[5][22] = 'Friday at 10 PM<br>Modern Rock<br>with DJ Werewolf';
    DH[5][23] = 'Friday at 11 PM<br>Modern Rock<br>with DJ Werewolf';
    // Add more when schedule is known. Note: there may be better ways to do this when information is known.
    
    
    function OnNow() {
    var thedate = new Date();
    var dayofweek = thedate.getDay();
    var hourofday = thedate.getHours();
    // alert(dayofweek+':'+hourofday+'<br />'+DH[dayofweek][hourofday]);
    var showOn = DH[dayofweek][hourofday];
    if (showOn == '') { showOn = thedate+'\n\nNo Show Scheduled'; }
    alert(showOn);
    }
    
    function NowON() {
    var thedate = new Date();
    var dayofweek = thedate.getDay();
    var hourofday = thedate.getHours();
    var showOn = DH[dayofweek][hourofday];
    if (showOn == '') { showOn = thedate+'<p />No Show Scheduled'; }
    [B]document.getElementById("NowOn").innerHTML = showOn;[/B]
    } 
    </script>
    </head>
    


    and the body HTML
    <BODY onLoad="NowON()">
    <!-- Unhide this if table display desired
    <script type="text/javascript">
    document.write(TableStationSchedule())
    </script>
    -->
    <script type="text/javascript">
    document.write(NowON());
    </script>
    <div id='NowOn' onClick="NowON()">Click For Now On KSWH</div> 
    </body>
    


    It works fine in all browers, but IE is bringing up the following message, but still loads it fine and still works
    Message: 'document.getElementById(...)' is null or not an object
    


    any help would be brill!!

    cheers


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    Thanks for posting in that format by the way, it's a lot easier to look at.

    I wonder if this is the problem:

    [html]
    <script type="text/javascript">
    document.write(NowON());
    </script>
    <div id='NowOn' onClick="NowON()">Click For Now On KSWH</div>
    [/html]

    You're calling the function twice - once in the onload event of the body and the bit above too. However, the code above is executing the function before the div is being written to the screen.

    So what might be happening is that it's failing the first time as the page is loading, but working the second time when it's called by the onload event (as the div is now in the DOM). Using document.write might also be causing problems, but you should just remove the line altogether.

    Quick tip - if you're not sure if an element will exist, you can just do the following:
    if (document.getElementById("NowOn"))
    {
        // your code in here
    }
    

    This will check to see if the element exists first.

    Also - indent your code; it's a lot easier to debug - even if it uses more lines.


  • Registered Users Posts: 1,459 ✭✭✭Heathen


    Thats working perfect now on all browsers.. Thanks a Mil Eoin :-)


  • Registered Users Posts: 21,257 ✭✭✭✭Eoin


    A pleasure :)


  • Advertisement
Advertisement