472,805 Members | 1,084 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 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 3092
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

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

Similar topics

6
by: Reid Goldsborough | last post by:
Hi. I'm a JavaScript neophyte. I'm trying to create a JPEG animation, with one coin (tet) morphing into another. The code doesn't work. Anybody feel like taking a shot at correcting me? It's short....
11
by: George Hester | last post by:
I have a css file this is a portion of it: /* trackaccept.css */ div.track { width:400px; height: 100px; } I have this in my ASP page:
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
9
by: beguigne | last post by:
Below is a snippet of a crude date picking routine for a form. I am a novice at this so, I am hitting my head at why when I select the day, the onChange event gives me a blank. What am I missing?...
9
by: optimistx | last post by:
Which url in your opinion would be a good or even the best example of javascript usage in a set of pages at least say 10 or more pages? How to use css, how to split js-code to files, how to code...
8
by: Frank | last post by:
Hi, I am working with VS.NET 2005 Ultimately, I wish to call a JavaScript function from a .js file
1
by: jadeite100 | last post by:
Hi: I am having problem passing an xsl param variable as a parameter to a javascript function inside an xsl styelsheet. Here is my xsl stylesheet. I am trying to pass a variable called...
3
by: Fresno Bob | last post by:
I have a page which is a master page. I want to trigger a Javascript function in the onload event of the body. Simply attaching an onload event to the body which points to javascript function...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.