| View previous topic :: View next topic |
| Author |
Message |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Tue Jul 16, 2002 6:48 am Post subject: Object Expected Error |
|
|
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://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
|
| Back to top |
|
 |
redmuff New member

Joined: 14 Apr 2005 Posts: 1
|
Posted: Thu Apr 14, 2005 8:14 am Post subject: |
|
|
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 |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
|
| Back to top |
|
 |
Priit New member

Joined: 31 Jan 2007 Posts: 3
|
Posted: Wed Jan 31, 2007 9:20 am Post subject: |
|
|
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 |
|
 |
theHighlander New member

Joined: 14 Mar 2007 Posts: 1 Location: Johannesburg, South Africa
|
Posted: Thu Mar 15, 2007 12:45 am Post subject: |
|
|
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 |
|
 |
danielrigano New member

Joined: 28 Jan 2008 Posts: 1 Location: la
|
Posted: Mon Jan 28, 2008 7:14 am Post subject: |
|
|
| Thanks for your tip.Really helpful. |
|
| Back to top |
|
 |
perfectlasers New member

Joined: 20 May 2010 Posts: 1 Location: Hong Kong
|
|
| Back to top |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Tue Jul 13, 2010 7:11 am Post subject: |
|
|
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://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.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 |
|
 |
Velosai New member

Joined: 03 Sep 2010 Posts: 2 Location: UK
|
Posted: Fri Sep 03, 2010 2:17 am Post subject: Most confusing error ... |
|
|
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 |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Fri Sep 03, 2010 2:59 am Post subject: |
|
|
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://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
Velosai New member

Joined: 03 Sep 2010 Posts: 2 Location: UK
|
Posted: Fri Sep 03, 2010 3:08 am Post subject: |
|
|
| 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 |
|
 |
phil karras Senior Member

Joined: 15 Jul 2002 Posts: 1776 Location: MD
|
Posted: Fri Sep 03, 2010 9:05 am Post subject: |
|
|
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://www.jsworkshop.com/posting.html
IHBAAA = It Has Been Asked And Answered
KISS: http://www.jsworkshop.com/bb/viewtopic.php?t=508 |
|
| Back to top |
|
 |
godfather001 New member

Joined: 09 Apr 2011 Posts: 1
|
Posted: Sat Apr 09, 2011 5:07 am Post subject: |
|
|
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 |
|
 |
Margarite New member

Joined: 14 Jan 2012 Posts: 1
|
Posted: Sat Jan 14, 2012 4:35 pm Post subject: |
|
|
| I ran into the same issue... Thanks for the info! |
|
| Back to top |
|
 |
|