IE throws JavaScript Error: The value of the property 'googleMapsQuery' is null or undefined, not a Function object (works in other browsers)
Asked Answered
R

6

12

I'm having a real problem with JavaScript scope in IE 9.

This is inside the body of my document (yes, I realize script should go in the head for proper HTML, but I've never had it break a script before). The script is in the body because I don't want to mess with a shared header page for a script that is only relevant for this page:

<script type="text/javascript">
function googleMapsQuery(accountNum) {
    // function code is here (omitted for brevity)
}
</script>

This is inside a td block inside a tr block inside a tbody block inside a table block inside a form block inside the body:

<button id="google-422111" onclick="googleMapsQuery(422111)" type="button">Google This!</button>

I even moved the script block above the form just in case the order of the script function declaration was relevant (it's not).

The script works flawlessly in FireFox and Chrome, but in IE 9 (with or without compatibility view on), I get this error:

SCRIPT5007: The value of the property 'googleMapsQuery' is null or undefined, not a Function object

I studied JavaScript scope, and I cannot figure out any reason why IE thinks that 'googleMapsQuery' is a property, and why it is undefined. It's a function, and I defined it!

Reef answered 12/4, 2012 at 17:49 Comment(2)
body is a perfectly fine place for script, at the bottom of the body is actually preferred :)Falstaffian
Script tags in the HEAD are processed synchronously (serially) before processing the body. Script tags in the body are loaded asynchronously, along with other scripts and the rest of the DOM nodes... I don't use the <button> tag, I use <input type="button">Malva
R
12

I found the answer, and in spite of what I reported, it was NOT browser specific. The bug was in my function code, and would have occurred in any browser. It boils down to this. I had two lines in my code that were FireFox/FireBug specific. They used console.log. In IE, they threw an error, so I commented them out (or so I thought). I did a crappy job commenting them out, and broke the bracketing in my function.

Original Code (with console.log in it):

if (sxti.length <= 50) console.log('sxti=' + sxti);
if (sxph.length <= 50) console.log('sxph=' + sxph);

Broken Code (misplaced brackets inside comments):

if (sxti.length <= 50) { //console.log('sxti=' + sxti); }
if (sxph.length <= 50) { //console.log('sxph=' + sxph); }

Fixed Code (fixed brackets outside comments):

if (sxti.length <= 50) { }//console.log('sxti=' + sxti);
if (sxph.length <= 50) { }//console.log('sxph=' + sxph);

So, it was my own sloppy coding. The function really wasn't defined, because a syntax error kept it from being closed.

Oh well, live and learn. ;)

Reef answered 13/4, 2012 at 19:43 Comment(0)
H
23

I was having a similar issue with a property being null or undefined.

This ended up being that IE's document mode was being defaulted to IE7 Standards. This was due to the compatibility mode being automatically set to be used for all intranet sites (Tools > Compatibility View Setting > Display Intranet Sites in Compatibility View).

Hike answered 15/7, 2013 at 11:28 Comment(1)
This helped me massively - this page was the first hit for a Google search of "The value of the property is null or undefined, not a Function object", and this was the solution I needed. So thanks!Plica
R
12

I found the answer, and in spite of what I reported, it was NOT browser specific. The bug was in my function code, and would have occurred in any browser. It boils down to this. I had two lines in my code that were FireFox/FireBug specific. They used console.log. In IE, they threw an error, so I commented them out (or so I thought). I did a crappy job commenting them out, and broke the bracketing in my function.

Original Code (with console.log in it):

if (sxti.length <= 50) console.log('sxti=' + sxti);
if (sxph.length <= 50) console.log('sxph=' + sxph);

Broken Code (misplaced brackets inside comments):

if (sxti.length <= 50) { //console.log('sxti=' + sxti); }
if (sxph.length <= 50) { //console.log('sxph=' + sxph); }

Fixed Code (fixed brackets outside comments):

if (sxti.length <= 50) { }//console.log('sxti=' + sxti);
if (sxph.length <= 50) { }//console.log('sxph=' + sxph);

So, it was my own sloppy coding. The function really wasn't defined, because a syntax error kept it from being closed.

Oh well, live and learn. ;)

Reef answered 13/4, 2012 at 19:43 Comment(0)
E
2

Have you tried adding the semicolon to onclick="googleMapsQuery(422111);". I don't have enough of your code to test if the missing semicolon would cause the error, but ie is more picky about syntax.

Ecclesiastic answered 12/4, 2012 at 18:6 Comment(1)
It wasn't the semi-colon. The function was really undefined due to some sloppy commenting and bracketing on my part. A true syntax error that would keep my script from even compiling if it were executable code. ;)Reef
S
2

In my particular case, I had a similar error on a legacy website used in my organization. To solve the issue, I had to list the website a a "Trusted site".

To do so:

  • Click the Tools button, and then Internet options.
  • Go on the Security tab.
  • Click on Trusted sites and then on the sites button.
  • Enter the url of the website and click on Add.

I'm leaving this here in the remote case it will help someone.

Serrulation answered 30/8, 2018 at 12:36 Comment(1)
i found this is useful in my case. i am maintaning some very old system which use vbscript and ocx (the system is too complicated to revamped over), spend 3 working days seraching for why user cannot access the site. nginx access log shows nothing peculiar, this answer helped me. +1 for that.Alchemize
L
1

So I had a similar situation with the same error. I forgot I changed the compatibility mode on my dev machine and I had a console.log command in my javascript as well. I changed compatibility mode back in IE, and removed the console.log command. No more issue.

Loftin answered 9/7, 2015 at 20:0 Comment(0)
S
-1

Just a few minutes ago i was facing the same problem. I got the problem that is after just placing your jQuery start the other jQuery scripting. After all it will work fine.

Scrape answered 19/6, 2013 at 7:47 Comment(1)
This answer makes no sense to me.Haag

© 2022 - 2024 — McMap. All rights reserved.