Entry
JavaScript: Error: What does error 'Object expected' possibly mean?
Apr 7th, 2008 23:57
ha mo, Graham Anderson, Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 20 September 2004 - 07:46 pm ------------------
JavaScript: Error: What does error 'Object expected' possibly mean?
---
Possible causes:
1. probably you forgot a 'function' or a variable
(=not added to your program)
e.g.
you write
ONCLICK=' FNMyFunction();'
and you forget to add this 'FNMyFunction' to your program
1.1. You are missing an external JavaScript file
--- cut here: begin --------------------------------------------------
<HTML>
<SCRIPT
LANGUAGE="JavaScript"
SRC="SomeNonExistingFile.js"
>
</SCRIPT>
</HTML>
--- cut here: end ----------------------------------------------------
1.2. you typed the wrong path to a JavaScript file
--- cut here: begin --------------------------------------------------
<HTML>
<SCRIPT
LANGUAGE="JavaScript"
SRC="c:/SomeWrongPath/YourFile.js"
>
</SCRIPT>
</HTML>
--- cut here: end ----------------------------------------------------
---
---
2. check the name (spelling) of the function
(upper case versus lower case)
of the function
(e.g. FNInstr() versus FNInStrI())
---
e.g.
you write
FNMyfunction() instead of the correct FNMyFunction()
(thus a lower case 'f', instead of upper case 'F')
---
e.g.
you write
a = Math.Random();
and because this random() is an inbuilt JavaScript function, which
should not be capitalized, you should instead have written
a = Math.random();
---
---
3. check if the parentheses are in balance
(same amount of open '(' and close ')' parentheses)
---
---
4. you have inserted extra spaces where it should not
e.g. here there are spaces inserted in front of
LANGUAGE = " javascript"
--- cut here: begin --------------------------------------------------
<HTML>
<BODY
ONLOAD = '
PROCTest();
'
>
<SCRIPT
LANGUAGE = " javascript"
>
function PROCTest() {
// do something
}
</SCRIPT>
</BODY>
</HTML>
--- cut here: end ----------------------------------------------------
So the correct code is (after removing the space in front of
javascript):
--- cut here: begin --------------------------------------------------
<HTML>
<BODY
ONLOAD = '
PROCTest();
'
>
<SCRIPT
LANGUAGE = "javascript"
>
function PROCTest() {
// do something
}
</SCRIPT>
</BODY>
</HTML>
--- cut here: end ----------------------------------------------------
---
---
5. If your Javascripts are in an external file, they may not be loading
before being called by in-line scripts.
Test by moving all your JS code inside the web page.
---
---
Possible solutions:
1. check if the involved definitions of the functions and or variables
can be found in the source code of that JavaScript program
(e.g. do a <CTRL><F> on that page, and type the function name)
If not, then if available, add them to your program.
2. Check if the name of the function or variable is written correctly.
3. Add or remove parentheses ( ) and or { }
4. Remove spurious spaces where necessary
----------------------------------------------------------------------
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com