Book Section
-----
TY JavaScript 3rd Ed.
Teach Yourself JS 1.5
Teach Yourself DHTML
Teach Yourself JS 1.3
LLWW: JavaScript

General Section
-----
Discussion Forum
Articles / Tips
JavaScript Links
About the Author
Privacy Policy
Contact Me



Other Sites
-----
Website Workshop
JavaScript Weblog

JavaScript Workshop Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Object Expected Error
Goto page 1, 2  Next
 
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles
View previous topic :: View next topic  
Author Message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Tue Jul 16, 2002 6:48 am    Post subject: Object Expected Error Reply with quote

Someone I was helping had the following error pop up on some browsers:

line ##
char 1
object expected

It turned out to be caused by a line like this:
Code:

<body gcolor="#BA8F3F" onLoad="My_preloadImages('image1.gif','image2.gif')">

This is because the function: My_preloadImages was not defined in this html file and was not loaded by a

<script language="JavaScript" src="MyFunctions.js">

type line either.

Once I made a dummy function of that name and placed it in the header section all was well, except of course that the images wanted were not in fact pre-loaded.

This Error Means:
(1) that for some reason a function expected has not been found. It could be that you mis-typed the name MyFunction is different from the following: myFunction, Myfunction, & myfunction to name but a few.
(2) It could be that the function was loaded but too late. Using something like:
Code:

<script ....>
   var = MyFunction();
</script>
.
.
.
<script ..... src='MyLib.js'>
  // Holds all my functions including MyFunction()
</script>

would cause this problem.
(3) An error occured before the function could be loaded which caused the rest of the script to abort. In some very strange cases this error might not be seen by you if the browser for some reason doesn't choke on it, yet all code following this error will NOT HAVE BEEN LOADED! - This has got to be the most difficult to locate, but I'd suggest that if everything looks OK to you, then simply move this function to the beginning of the <script> section and see what happens. By moving each piece from the bottom to the top (one piece at a time) you will eventually be able to locate the defective section.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Mon Apr 07, 2003 11:05 am    Post subject: Reply with quote

Another variation is:

Hints on, Error: Object Does Not Exist
http://jsworkshop.com/bb/viewtopic.php?p=2787
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
redmuff
New member
New member


Joined: 14 Apr 2005
Posts: 1

PostPosted: Thu Apr 14, 2005 8:14 am    Post subject: Reply with quote

dude, I fixed this it was really wierd, never seen it before

the browser wasnt accepting the following function template

function doSomething()
{
//do something here
}


it would only accept

function doSomething(){
//do something here
}


notice the difference? the '{' tag had to be on the same line as the function declaration.

This happened when I was doing it as part of an xsl transformation, but I doubt that had anything to do with it.
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Mon May 09, 2005 6:49 pm    Post subject: Reply with quote

Interesting, I would never have tripped over that one since I always
use:

function name () {
}

PK
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Priit
New member
New member


Joined: 31 Jan 2007
Posts: 3

PostPosted: Wed Jan 31, 2007 9:20 am    Post subject: Reply with quote

Just registered to give this feedback cause it took me some time to figure this out.

Hints on, Error: Object Does Not Exist

This Error Means:
(4) JavaScript fie was not loaded because it contained errors.

Example:
If MyFunctions.js would contain errors before function My_preloadImages then this file is loaded partially (until the error) or is not loaded at all (not sure). and if you try to call this function in html contained script then you get Object not found and a line pointer to the html line where function was called.

So don't mess up your .js file
Back to top
View user's profile Send private message
theHighlander
New member
New member


Joined: 14 Mar 2007
Posts: 1
Location: Johannesburg, South Africa

PostPosted: Thu Mar 15, 2007 12:45 am    Post subject: Reply with quote

Hi All,

Just thought I would register and add this suggestion in case anyone else made this most ridiculouse of mistakes. (To many late nights)

make sure that if you are linking your script type is set to "text/javascript", no "application/x-javascript". Otherwise you will also get the "object not found" error.

Cheers
Theunis
Back to top
View user's profile Send private message
danielrigano
New member
New member


Joined: 28 Jan 2008
Posts: 1
Location: la

PostPosted: Mon Jan 28, 2008 7:14 am    Post subject: Reply with quote

Thanks for your tip.Really helpful.
Back to top
View user's profile Send private message Visit poster's website
perfectlasers
New member
New member


Joined: 20 May 2010
Posts: 1
Location: Hong Kong

PostPosted: Thu May 20, 2010 10:33 pm    Post subject: useful tip Reply with quote

cool! it's very useful tips, thank you very much.
_________________
laser pointer,green laser pointer, astronomy laser pointer can be used in astronomy, military and scientific research.
Back to top
View user's profile Send private message Visit poster's website
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Tue Jul 13, 2010 7:11 am    Post subject: Reply with quote

Just a quick note, the (4) entered by Priit is simply a sub-set of my (3) but it is none-the-less a good point to state on its own.

Any js file being loaded will kill everything, itself and any other file further down the line if it has a bug in it that causes it not to load into the calling file/html.

Thanks Priit!

11/24/2011: I did some tests this past week and found that any JavaScript error no matter where it is in the script section, or file, will cause all JavaScript to be trashed, meaning even functions or vars declared before the error will come up as "Object Expected" etc. At least in IE 7, haven't yet checked IE 8, or Firefox any version.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508


Last edited by phil karras on Thu Nov 24, 2011 8:16 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Velosai
New member
New member


Joined: 03 Sep 2010
Posts: 2
Location: UK

PostPosted: Fri Sep 03, 2010 2:17 am    Post subject: Most confusing error ... Reply with quote

Guys,

Hopefully you can see the error that I am obviously blind to, I keep getting Object Expected, but I don't understand why ... the code snippets are

Code:
<SCRIPT LANGUAGE="text/javascript">
  function edit_rec(U, S, E, V){
    alert ('start edit');
    var win = window.open("page.asp?Unit=" + U + "&Start=" + S + "&End=" + E + "&Event=" + V, "", "Load of opening arguements");
  }
</SCRIPT>


Code:
<SPAN onClick="alert('Call Edit'); edit_rec('1','2','3','4');">text</SPAN>


The script block is now at the top of the HEAD and all I am getting it the first alert, before getting the object expected error ... any ideas?

Thanks
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Fri Sep 03, 2010 2:59 am    Post subject: Reply with quote

I get:

"Can not find file '...../page.asp?Unit=1&...Event=4'. Make sure the path or Internet address is correct."

So it's getting to & through your function, and of course I do not have the asp page, but if you do have it the missing Object is probably in there.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
Velosai
New member
New member


Joined: 03 Sep 2010
Posts: 2
Location: UK

PostPosted: Fri Sep 03, 2010 3:08 am    Post subject: Reply with quote

Thanks for that Phil ... and that is what I would expect it to do (As I havn't actually created the next page yet) ... but I can't for the life of me to get it so that the second alert comes up, let alone can't find the page ...
Back to top
View user's profile Send private message
phil karras
Senior Member
Senior Member


Joined: 15 Jul 2002
Posts: 1750
Location: MD

PostPosted: Fri Sep 03, 2010 9:05 am    Post subject: Reply with quote

Well all I did was make a blank html file, nothing else in it & ran it.

I'm using IE 7 for this test haven't tried anything else yet, let me know what you're using.



Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 <title>help319.htm - Object Expected Error</title>

 <script language='JavaScript' type='text/javascript'> <!--
   function edit_rec(U, S, E, V){
      alert ('start edit');
      var win = window.open("page.asp?Unit=" + U + "&Start=" + S + "&End=" + E + "&Event=" + V, "", "Load of opening arguements");
   }

 // --> </script>
</head>

<body>

  <SPAN onClick="alert('Call Edit'); edit_rec('1','2','3','4');">text</SPAN>

</body>
</html>


The two alerts popup then the error message about the missing asp page, then the debugger starts & asks if I want to debug using a new VisualStudio 2008, when I say yes it pops to the
Code:
var win = window.open("page.asp?Unit=" + U + "&Start=" + S + "&End=" + E + "&Event=" + V, "", "Load of opening arguements");
line, which is where the error is because of a nonexistant asp page. So nothing new there.
_________________
Phil K
Circle Software Consulting
Test website: http://cs.yrex.com/
Guidelines for Posting: http://jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://jsworkshop.com/bb/viewtopic.php?t=508
Back to top
View user's profile Send private message Visit poster's website
godfather001
New member
New member


Joined: 09 Apr 2011
Posts: 1

PostPosted: Sat Apr 09, 2011 5:07 am    Post subject: Reply with quote

You just save my life. I was going to give it up. I would never think that
Code:
function myFunction() {

}

and

Code:
function myFunction()
{
}


are not the same.

By the way, is there a standard, because i know that you can also write

Code:
var myFunction = function() {

}

_________________
how to javascript
Back to top
View user's profile Send private message
Margarite
New member
New member


Joined: 14 Jan 2012
Posts: 1

PostPosted: Sat Jan 14, 2012 4:35 pm    Post subject: Reply with quote

I ran into the same issue... Thanks for the info!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    JSWorkshop Forum Index -> Articles All times are GMT - 7 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
(c) 1997-2002 Starling Technologies and Michael Moncur. Portions (c) Sams Publishing.