470,643 Members | 1,348 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,643 developers. It's quick & easy.

Error in Array in IE

I get the following error in IE but not in Netscape. The code works,
and the error only shows up if you click on the icon in the bottom
left corner of the screen, next to where it says Error on Page... I
would like to know what the error means and how to fix it.

The site is at www.tricityarena.com

error ae[...].0' is null or not an object

here is my code
var today = new Date();
var dayarray=new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray=new
Array("Jan","Feb","Mar","Apr","May","Jun","Jul","A ug","Sep","Oct","Nov
","Dec")

document.write('<table>');

var ae=new Array();

ae[10]=new Array("2004/1/16 23:59:59","<b>Stick and Puck Hockey<\/b> -
11:30am-1:00pm");
ae[9]=new Array("2004/3/26 23:59:59","<b>Diesel Football Home
Opener<\/b> vs Casper, WY - 7:30 pm");
for (var i=ae.length-1;i>=0;i--)
{
var date = new Date(ae[i][0])
var year = 1900 + date.getYear()%1900 // < AD 3800
if (today.getTime() <= date.getTime()) {
document.write('<tr><td valign=top>' + dayarray[date.getDay()]+",
"+montharray[date.getMonth()]+" "+date.getDate()+", "+year+" " +
'&nbsp;&nbsp;</td><td> ' + ae[i][1] + '</td></tr>');
document.write('<tr><td colspan="2">&nbsp;</td></tr>');
}
}

document.write('</table>');


Jul 20 '05 #1
6 1553
"Treetop" <tr*****@netfront.net> wrote in message
news:bu************@ID-221536.news.uni-berlin.de...
I get the following error in IE but not in Netscape. The code works,
and the error only shows up if you click on the icon in the bottom
left corner of the screen, next to where it says Error on Page... I
would like to know what the error means and how to fix it.

The site is at www.tricityarena.com

error ae[...].0' is null or not an object

here is my code

[ ...snip ... ]


var ae=new Array();

ae[10]=new Array("2004/1/16 23:59:59","<b>Stick and Puck Hockey<\/b> -
11:30am-1:00pm");
ae[9]=new Array("2004/3/26 23:59:59","<b>Diesel Football Home
Opener<\/b> vs Casper, WY - 7:30 pm");
for (var i=ae.length-1;i>=0;i--)
{
var date = new Date(ae[i][0])
var year = 1900 + date.getYear()%1900 // < AD 3800
if (today.getTime() <= date.getTime()) {
document.write('<tr><td valign=top>' + dayarray[date.getDay()]+",
"+montharray[date.getMonth()]+" "+date.getDate()+", "+year+" " +
'&nbsp;&nbsp;</td><td> ' + ae[i][1] + '</td></tr>');
document.write('<tr><td colspan="2">&nbsp;</td></tr>');
}
}

document.write('</table>');


Your array contains ae[10] and ae[9] yet your 'for' loop starts and ends at
ae[1] - therein lies your problem.
Jul 20 '05 #2
On Thu, 22 Jan 2004 09:25:15 -0600, Treetop <tr*****@netfront.net> wrote:
[indentation and new lines fixed; whitespace added between operators]
var today = new Date();
var dayarray = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec")

document.write('<table>');

var ae = new Array();

ae[10] = new Array("2004/1/16 23:59:59",
"<b>Stick and Puck Hockey<\/b> - 11:30am-1:00pm");
ae[9] = new Array("2004/3/26 23:59:59",
"<b>Diesel Football Home Opener<\/b> vs Casper, WY - 7:30 pm");

for (var i = ae.length - 1; i >= 0; i--) {
var date = new Date( ae[i][0] )
var year = 1900 + date.getYear() % 1900 // < AD 3800
if (today.getTime() <= date.getTime()) {
document.write('<tr><td valign=top>' + dayarray[date.getDay()] +
"," + montharray[date.getMonth()] + " " + date.getDate() +
", " + year + " " + '&nbsp;&nbsp;</td><td> ' + ae[i][1] +
'</td></tr>');
document.write('<tr><td colspan="2">&nbsp;</td></tr>');
}
}

document.write('</table>');


The algorithm, as implemented is not at fault, but your test data is. The
loop will start at 9 (the last element in the array) and attempt to
decrement to 0. This is fine, for a fully working example, but your test
data only goes to 8. As soon as the browser tries to resolve element 7, it
finds that there's no data and gives you the error. If you've only got two
pieces of test data, you can't create an array with ten elements.

Some suggestions:

- Make sure you add all the necessary semi-colons (;). There are a few
statements above that don't have them, and while technically legal (in
certain circumstances), it is still good style to include them.
- Your 'ae' array isn't much of an array. However, it would make a good
object. Consider revising it.
- Some of the forward-slashes that compose the closing tags you will
insert have been escaped, which is good. However, the majority haven't.
Make sure you change all instances of '</' to '<\/'.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
"Treetop" <tr*****@netfront.net> wrote in message news:<bu************@ID-221536.news.uni-berlin.de>...
I get the following error in IE but not in Netscape.
Netscape is being overly friendly and hiding your bug.
error ae[...].0' is null or not an object

here is my code

var ae=new Array();

ae[10]=new Array("2004/1/16 23:59:59","<b>Stick and Puck Hockey<\/b> -
11:30am-1:00pm");
ae[9]=new Array("2004/3/26 23:59:59","<b>Diesel Football Home
Opener<\/b> vs Casper, WY - 7:30 pm");
for (var i=ae.length-1;i>=0;i--)
{
var date = new Date(ae[i][0])


You only put values in elements 9 and 10. So when i = 8, ae[8] is null
and ae[8][0] is undefined.
Jul 20 '05 #4

"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
On Thu, 22 Jan 2004 09:25:15 -0600, Treetop <tr*****@netfront.net> wrote:
[indentation and new lines fixed; whitespace added between operators]
var today = new Date();
var dayarray = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat") var montharray = new Array("Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec")

document.write('<table>');

var ae = new Array();

ae[10] = new Array("2004/1/16 23:59:59",
"<b>Stick and Puck Hockey<\/b> - 11:30am-1:00pm");
ae[9] = new Array("2004/3/26 23:59:59",
"<b>Diesel Football Home Opener<\/b> vs Casper, WY - 7:30 pm");

for (var i = ae.length - 1; i >= 0; i--) {
var date = new Date( ae[i][0] )
var year = 1900 + date.getYear() % 1900 // < AD 3800
if (today.getTime() <= date.getTime()) {
document.write('<tr><td valign=top>' + dayarray[date.getDay()] + "," + montharray[date.getMonth()] + " " + date.getDate() +
", " + year + " " + '&nbsp;&nbsp;</td><td> ' + ae[i][1] +
'</td></tr>');
document.write('<tr><td colspan="2">&nbsp;</td></tr>');
}
}

document.write('</table>');
The algorithm, as implemented is not at fault, but your test data

is. The loop will start at 9 (the last element in the array) and attempt to
decrement to 0. This is fine, for a fully working example, but your test data only goes to 8. As soon as the browser tries to resolve element 7, it finds that there's no data and gives you the error. If you've only got two pieces of test data, you can't create an array with ten elements.
by changing the array so the last number is a 0 now did the trick.
Thanks everyone

Some suggestions:

- Make sure you add all the necessary semi-colons (;). There are a few statements above that don't have them, and while technically legal (in certain circumstances), it is still good style to include them.
The day and month arrays have semi-colons on them now. Are there any
other statements that I have missed?
- Your 'ae' array isn't much of an array. However, it would make a good object. Consider revising it.
I am affraid that I don't understand. What is an object? Is it an
element such as a VAR? ( I am very new to javascript. I learn by
taking other scripts and learning what they do, then create my own )
How is this different from an Array?
- Some of the forward-slashes that compose the closing tags you will
insert have been escaped, which is good. However, the majority haven't. Make sure you change all instances of '</' to '<\/'.


I asked this group a while ago the difference between </ and <\/ and
the impression I got is that the <\/ is not used.


Jul 20 '05 #5
> > - Your 'ae' array isn't much of an array. However, it would make a
good object. Consider revising it.
I am affraid that I don't understand. What is an object? Is it an
element such as a VAR? ( I am very new to javascript. I learn by
taking other scripts and learning what they do, then create my own )
How is this different from an Array?
This is the worst possible way to learn this language. Most of the scripts out
there are dreadful. Much of what you are learning is wrong. You are missing some
really important knowledge. You are picking up some very bad habits.

There is a good book out there by Flanagan. Get the 4th edition of it.
Meanwhile, check this out to find the difference between an object and array:
http://www.crockford.com/javascript/survey.html

The object is one of the central ideas in JavaScript. Programming without is
like driving a car without knowing what the pedals do.
- Some of the forward-slashes that compose the closing tags you will
insert have been escaped, which is good. However, the majority
haven't. Make sure you change all instances of '</' to '<\/'.

I asked this group a while ago the difference between </ and <\/ and
the impression I got is that the <\/ is not used.


You got the wrong impression. <\/ should be used in strings in html files. This
tool will help you find them all: http://www.crockford.com/javascript/lint.html

Jul 20 '05 #6
On Thu, 22 Jan 2004 19:49:26 GMT, Treetop <tr*****@netfront.net> wrote:
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message
news:op**************@news-text.blueyonder.co.uk...
- Make sure you add all the necessary semi-colons (;). There are a
few statements above that don't have them, and while technically
legal (in certain circumstances), it is still good style to include
them.


The day and month arrays have semi-colons on them now. Are there any
other statements that I have missed?


The two statement that begin "var date=" and "var year =" at the start of
the for-loop.
- Your 'ae' array isn't much of an array. However, it would make a
good object. Consider revising it.


I am affraid that I don't understand. What is an object? Is it an
element such as a VAR? ( I am very new to javascript. I learn by
taking other scripts and learning what they do, then create my own )
How is this different from an Array?


There are plenty of resources concerning the Object-Oriented Paradigm[1]
on the Internet and in books (Mr Crockford gave you one of each). Most
modern programming languages incorporate it in some way, including
JavaScript. It is certainly something worth while learning.

Briefly, objects are a way of abstracting something within a program. You
can take a complex, real-life system and break it down into properties
(attributes) that describe the entity, and the actions (methods) that it
can perform.

The arrays that your 'ae' array contained, represented events in a
recreation centre (of some description). Though not 'complex', those
events compose a real-life system, and they have properties; in this case
the time of the event and it's name.

Though possibly over-kill for something so simple, an object is a more
logical and appropriate representation for the events.
- Some of the forward-slashes that compose the closing tags you will
insert have been escaped, which is good. However, the majority
haven't. Make sure you change all instances of '</' to '<\/'.


I asked this group a while ago the difference between </ and <\/ and
the impression I got is that the <\/ is not used.


To be honest, I wasn't sure if this was another old hold-over (like script
hiding). It certainly wouldn't have done anything negative, other than
adding a byte to the file size. However, Mr Crockford just cleared that up.

The only time that you can avoid escaping the '</' sequence in a string is
in external script files. If the script is inline, you need to escape to
'<\/'.

Mike

[1] You'll also find information under Object-oriented Programming.

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Keiron Waites | last post: by
3 posts views Thread by Victor | last post: by
669 posts views Thread by Xah Lee | last post: by
11 posts views Thread by Andrew Poelstra | last post: by
9 posts views Thread by Gary Wessle | last post: by
Dormilich
2 posts views Thread by Dormilich | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.