473,394 Members | 1,709 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

'Object' is undefined

Iam trying to make the devshed tutorial for JavaScrip Object lesson to
work in my PC. The calendar.js file has the object 'Calendar'
constructed but when I called using the below html doc, I get the
"Calendar' is undefined error for line 6 and 7, where the obj1 and
obj2 are specified.
The full code of the calendar.js is in
http://www.devshed.com/Client_Side/J...ect/page9.html

Both the files are in the same directory. Iam using Windows 2000
Professional with IE6.

Appreciate any help to resolve this problem.

<html>
<head>
<script language="JavaScript" src="calendar.js"></script>
</head>
<body bgcolor="white">
<script> obj1 = new Calendar(2, 2005); </script>
<script> obj2 = new Calendar(7, 2001); </script>
</body>
</html>
TIA

Sam
Jul 20 '05 #1
7 20221
In article <4d**************************@posting.google.com >, sa**@freeddns.org
(sams) writes:
Appreciate any help to resolve this problem.
<head>
<script language="JavaScript" src="calendar.js"></script>
</head>

<script> obj1 = new Calendar(2, 2005); </script>
<script> obj2 = new Calendar(7, 2001); </script>


Its a timing issue. You are trying to call the new Calendar() function before
the calendar.js file has loaded to the point that it exists. Try using the
onload to fire them off, and it should solve the undefined object errors.
--
Randy
Jul 20 '05 #2
hi************@aol.com (HikksNotAtHome) writes:
Its a timing issue. You are trying to call the new Calendar() function before
the calendar.js file has loaded to the point that it exists. Try using the
onload to fire them off, and it should solve the undefined object errors.


That is unlikely. The script is loaded and executed before parsing
continues. Some browsers allow parsing to continue earlier by adding
the defer attribute to the script tag, but it will still stop at the
next non-defer script tag.

A more likely problem is that "calendar.js" is a verbatim copy of the
script on the referred page ... including the <script> tag.

In an external JS file, you must not have
<script language="JavaScript">
at the beginning and </script> at the end. That will give syntax errors
that will prevent the file from being executed.

The page at devshed.com is slightly misguiding in that it gives the
code with <script> tags around, but later gives code that uses it
as an external file.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
In article <r8**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
hi************@aol.com (HikksNotAtHome) writes:
Its a timing issue. You are trying to call the new Calendar() function

before
the calendar.js file has loaded to the point that it exists. Try using the
onload to fire them off, and it should solve the undefined object errors.


That is unlikely. The script is loaded and executed before parsing
continues. Some browsers allow parsing to continue earlier by adding
the defer attribute to the script tag, but it will still stop at the
next non-defer script tag.


So if I load 100 .js files, then nothing will happen until all 100 of those
files are loaded? Or am I understanding wrong?

I know the onload event handler won't fire until the entire page is loaded, but
I seem to recall having problems where I was trying to call functions that had
not been downloaded from an external .js file in the past. Using the body's
onload to call them solved my problems.

Although, with regards to the OP, I didn't look at the .js file to see if it
had the most common error - the script tags in it.
--
Randy
Jul 20 '05 #4
hi************@aol.com (HikksNotAtHome) writes:
So if I load 100 .js files, then nothing will happen until all 100
of those files are loaded? Or am I understanding wrong?
That is correct. You can check it with only one JS file where you do
something boring like counting to a hundred million.

<h1>Header</h1>
<script type="text/javscript" src="longjs.js"></script>
<!-- script contains
for (var i=0;i<100000000;i++) {var x=i;}
-->
<h1>Header</h1>
I know the onload event handler won't fire until the entire page is
loaded, but I seem to recall having problems where I was trying to
call functions that had not been downloaded from an external .js
file in the past. Using the body's onload to call them solved my
problems.
If you could remember which browser you were using, it's worth
testing.

Waiting for the scripts to finish is actually necessary, since they
can contain document.write's, and even document.write's writing new
script tags that can define functions that the next script tag will
need.
Although, with regards to the OP, I didn't look at the .js file to
see if it had the most common error - the script tags in it.


It's a guess. He didn't show us his .js file, but from the description
he seemed to be following, it is a likely mistake.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
In article <ll**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
writes:
hi************@aol.com (HikksNotAtHome) writes:
So if I load 100 .js files, then nothing will happen until all 100
of those files are loaded? Or am I understanding wrong?
That is correct. You can check it with only one JS file where you do
something boring like counting to a hundred million.


It seems the one I used to test it was a simple array file that had 30k or so
entries, and tried to process it before the page loaded and got errors (NS6 I
think, but don't remember for sure). Since NS6 is basically old now, it may be
something that got changed in NS7, or, I could be remembering the browser
wrong.
I know the onload event handler won't fire until the entire page is
loaded, but I seem to recall having problems where I was trying to
call functions that had not been downloaded from an external .js
file in the past. Using the body's onload to call them solved my
problems.


If you could remember which browser you were using, it's worth
testing.


I think it was NS6 but not absolutely positive. Its been about a year or so,
and didn't really worry with it anymore, just moved it to the onload and went
on as a happy camper :)
Waiting for the scripts to finish is actually necessary, since they
can contain document.write's, and even document.write's writing new
script tags that can define functions that the next script tag will
need.


necessary or desirable? I can't see where the browser could know that it would
be necessary to wait. If it could, it could be assumed that the browser should
know to wait for the page to load before executing scripts, as it may need an
element in the body that doesn't exist yet. But I can see the logic behind not
executing more script until the last script loads though.
Although, with regards to the OP, I didn't look at the .js file to
see if it had the most common error - the script tags in it.


It's a guess. He didn't show us his .js file, but from the description
he seemed to be following, it is a likely mistake.


Isn't it just grand trying to debug code you can't see? <g>
--
Randy
Jul 20 '05 #6
"HikksNotAtHome" <hi************@aol.com> wrote in message
news:20***************************@mb-m06.aol.com...
In article <ll**********@hotpop.com>, Lasse Reichstein Nielsen <lr*@hotpop.com>
<snip>It seems the one I used to test it was a simple array file that
had 30k or so entries, and tried to process it before the page
loaded and got errors (NS6 I think, but don't remember for sure).
Since NS6 is basically old now, it may be something that got
changed in NS7, or, I could be remembering the browser wrong.

<snip>

I remember having timing problems with Netscape 6.2 loading a 90k array
in a JS file, so I think you have the right browser.

Richard.
Jul 20 '05 #7
> In an external JS file, you must not have
<script language="JavaScript">
at the beginning and </script> at the end. That will give syntax errors
that will prevent the file from being executed.


Thank you, I removed the <Script></script> tags from the .js file and
no other change. It worked. Great.

Apprecite all your help.

Sam
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
1
by: s_m_b | last post by:
here's the code (running from an ASP page): <script language = "JavaScript" type="text/javascript"> function initStuff() { var scanWindow = window.open('scanning.htm', 'scanning',...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
16
by: Java script Dude | last post by:
Creating a method of object (Object.prototype.classOf ...) is not the correct way because of a (as expected) flaw in IE where DOM Elements does not inherit from Object. As a result it is best to...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
7
by: Ike | last post by:
Can someone please illuminate to me why, in the following snippet of script, the alert statement in the try-catch gives me ? The file 'http://localhost:1222/roomx1/getdata.php' truly does exist....
19
by: brasilino | last post by:
Hi Folks: I've been looking (aka googling) around with no success. I need a usability beyond 'pop()' method when removing an Array elements. For example: oName = new...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
0
by: hott5hotj | last post by:
in Actionscript 3.0 Ive created a datagrid that populated with data. I want to create a pop up window to confirm whether the removal of an entry. When I call from the child object the following, I...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.