471,092 Members | 2,192 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 software developers and data experts.

Javascript - OnLoad is wrong in IE! Very frustrated.

Here is the site in question:

http://www.sws.vxcomputers.com/h2k/

Basically, on the left, you'll see a roster (them images) and you have to click the "Counter-Strike" link for it to load the images/names. However, I overcome this by executing what is usually the OnClick event on the OnLoad event instead. This works great in firefox - meaning there is no need to click the link to see the
proper images and not the filler images - it just comes up straight away like that.

However, when I added this onload event I get an error in IE7 - and I am still required to click the link to see the images/names. Here is the error:

Line: 54
Char: 19
Error: '_rosterlists' is null or not an object
Code: 0
URL: http://www.sws.vxcomputers.com/h2k/index.php

Ive tried numerous things like positioning what was the OnClick event at the end of the page etc...none work. Is there a way to check that the page is fully loaded? Also my index.php includes header.php, then the content then footer.php. So maybe header.php could check if footer.php is loaded then execute the javascript?

I tried putting the javascript code in footer.php (not the same file whereby the main code is for the roster section) and that has no effect in either browser.

Here is the code in header.inc.php:

[HTML]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title><?php echo $website_title; ?></title>
<meta name="Author" content="(c) 2003/2004 ">
<meta http-equiv="imagetoolbar" content="no">
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
<link rel="StyleSheet" href="css/smt8.css">
<script type="text/javascript" src="css/sortable.js"></script>
<style type="text/css">
/* Sortable tables */
table.sortable a.sortheader {
cursor: hand;
cursor: display;
}
table.sortable span.sortarrow {
color: black;
font-weight: bold;
text-decoration: none;
display: none;
}
</style>
<script type="text/javascript" src="css/scripts.js"></script>
</head>
<body onLoad="_active = 'roster-css'; updateLists(); return false">
<div id="container">
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="959" height="215" id="header" style="display: block;">
<param name="allowScriptAccess" value="sameDomain" />

<param name="movie" value="header.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#bbbbbbb" />
<embed SRC="header.swf" QUALITY="high" BGCOLOR="#ffffff" WIDTH="959" HEIGHT="215" NAME="header" ALLOWSCRIPTACCESS="sameDomain" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" STYLE="display: block;">
</object>

<div id="rightContent">
<h1 class="teamRoster"></h1>

<div id="rosterheading">
<div id="rosterlinks">
<?php
$games = getRosterGames();
$count = count($games);
foreach ($games as $i => $game) {
list($short, $full) = $game; ?>
<a href="#" onClick="_active = 'roster-<?= $short ?>'; updateLists(); return false"><?= $full ?></a> <?php if ($i + 1 != $count) { ?> | <?php } ?>
<?php } ?>
</div>
</div>
<?php foreach (getRosterLists() as $i => $filename) { ?>
<ul id="<?= basename($filename, '.txt') ?>" style="display: <?= ($i == 0 ? 'block' : 'none') ?>;" class="rosterlist">
<?php getTXT(basename($filename, '.txt')); ?>
</ul>
<?php } ?>
<br style="clear: both;" />
<a href="roster.php" class="more roster"></a>

<h1 class="latestmedia"></h1>

<ul>
<?php getTXT("media"); ?>
</ul>
<a href="roster.php" class="more latestmedia"></a>
<h1 class="quicklinks"></h1>

<ul>
<?php getTXT("links"); ?>
</ul>
<a href="links.php" class="more latestmedia"></a>

</div>
<div id="mainContent">
<h1 class="mainContent"></h1>

[/HTML]

The stuff regarding the roster section is the bit starting with "$games = getRosterGames();"

And here is the JS file that is included (you'll notice it mentions more than 1 but the other is irrelevant):

Expand|Select|Wrap|Line Numbers
  1.  
  2. addEvent(window, "load", rosterlist_fix);
  3.  
  4.  
  5.  
  6. var _rosterlists;
  7.  
  8. var _active;
  9.  
  10.  
  11.  
  12. function rosterlist_fix() {
  13.  
  14.   var lists = document.getElementById('rightContent').getElementsByTagName('ul');
  15.  
  16.   var list;
  17.  
  18.  
  19.  
  20.   var rosterlists = new Array();
  21.  
  22.  
  23.  
  24.   for (var i = 0; list = lists[i]; i++) {
  25.  
  26.     if (list.className == 'rosterlist')
  27.  
  28.       rosterlists[rosterlists.length] = list;
  29.  
  30.   }
  31.  
  32.  
  33.  
  34.   _rosterlists = rosterlists;
  35.  
  36.  
  37.  
  38.   _active = _rosterlists[0].id;
  39.  
  40.  
  41.  
  42.   updateLists();
  43.  
  44. }
  45.  
  46.  
  47.  
  48. function updateLists() {
  49.  
  50.   var ul;
  51.  
  52.  
  53.  
  54.   for (var i = 0; ul = _rosterlists[i]; i++) {
  55.  
  56.     if (ul.id != _active)
  57.  
  58.       ul.style.display = 'none';
  59.  
  60.     else
  61.  
  62.       ul.style.display = 'block';
  63.  
  64.   }
  65.  
  66. }
  67.  
  68.  

Help?!!

I just need "_active = 'roster-css'; updateLists(); return false" to load when the page is done loading - but IE isn't liking it in OnLoad!
Sep 7 '07 #1
6 3038
Logician
210 100+

Line: 54
Char: 19
Error: '_rosterlists' is null or not an object
Code: 0
URL: http://www.sws.vxcomputers.com/h2k/index.php
This is from the Opera console:
Here 2 Kill Clan
http://www.sws.vxcomputers.com/h2k/
Event thread: load
Error:
name: TypeError
message: Statement on line 53: Could not convert undefined or null to object
Backtrace:
Line 53 of linked script http://www.sws.vxcomputers.com/h2k/css/scripts.js
for (var i = 0;ul = _rosterlists[i];i++)
Line 1 of script
_active = "roster-css";
updateLists();
return false;

Either it doesn't like the test, or _rosterlists has no elements. You need to test that.
Sep 7 '07 #2
pbmods
5,821 Expert 4TB
Heya, Adam. Welcome to TSDN!

Everywhere else in your script, you use 'rosterlists'. That one line is the only place you use '_rosterlists'. Is this intentional?

PS. You can make your JavaScript easier to read by using special JavaScript CODE tags:

[CODE=javascript]
JavaScript code goes here.
[/code]
Sep 8 '07 #3
It is intentional. If you look in the header.inc.php file - you'll notice the onclick event is _rosterlists. Hence why I'm trying to run the same command OnLoad.

Also in scripts.js - "_rosterlists = rosterlists"

I know little of javascript - so I dont understand at all why this doesnt work.
Sep 8 '07 #4
pbmods
5,821 Expert 4TB
Heya, Adam.

My guess is that document.onload() fires before window.onload(), so when updateLists() runs, rosterlist_fix() hasn't been evaluated yet, so _rosterlists is undefined.
Sep 8 '07 #5
Yes! I have fixed it. What I did:

1. Remove the OnLoad event.
2. In scripts.js, replace:

Expand|Select|Wrap|Line Numbers
  1.   _active = _rosterlists[0].id;
  2.  
With:

Expand|Select|Wrap|Line Numbers
  1.   _active = 'roster-css'; updateLists(); return false
This works in both IE and firefox. For your help all!
Sep 8 '07 #6
pbmods
5,821 Expert 4TB
Heya, Adam.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Sep 8 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Reid Goldsborough | last post: by
11 posts views Thread by George Hester | last post: by
9 posts views Thread by beguigne | last post: by
9 posts views Thread by optimistx | last post: by
8 posts views Thread by Frank | last post: by
3 posts views Thread by Fresno Bob | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.