Object doesn’t support this property or method javascript error

In some browsers it would throw a “silent” error and stop executing javascript code. If you try to open page in IE in debug mode it would alert error message like this:

Object doesn’t support this property or method

I faced such problem today when i performed a calculation and assigned the calculated value to a variable without initializing the variable. In IE8 and Safari 5.0.2 the page just stopped to respond to javascript calls after a certain point of execution. Here’s what i had been trying to do.

container = Math.round(total/9.5);

after i added var to the variable container to look it like var container = Math.round(total/9.5); it started to work in IE and Safari. Fyi, it worked just fine in Firefox 4.0.1, Opera 11.10 and Chrome 11.0 with variable without var declaration.

Also, i remember (not very much sure but i think it happened) that at a place within the same code i had been trying to divide 0(zero) by a number and it threw a similar Object doesn’t support this property or method error. This is what i had been trying to do:

var total = parseFloat($("#SubTotal").val());
var remainder = (total/9.5) - Math.round(total/9.5);

In case when variable total held 0(zero) it would throw me similar error i.e. Object doesn’t support this property or method in IE and stopped working. Also in Safari it stopped working without showing any error message. Once i added a code line between those two lines, looking like the code below, it started working just fine and stopped showing an error in IE.

var total = parseFloat($("#SubTotal").val());
if(total<=0) return 0;// or something similar
var remainder = (total/9.5) - Math.round(total/9.5);

I do reckon that it happen to me and i had to fix it but right now even if i comment the if(total<=0) return 0; line out it still works fine. Seeking comments from you guys to throw some light on these issues.

Thanks.

2 thoughts on “Object doesn’t support this property or method javascript error

  1. I had the same situation as you. I was assigning a non-declared variable to a calculation. I was searching stackoverflow for an answer to my IE 8 dilemma and couldn’t find the answer. Thanks again you saved me hours of debugging time! :D

  2. Thanks thought I was done on IE 8 with the Object doesn’t support this property or method error message. Just adding the var did the trick. IE is must more picking than firefox and chrome

Leave a Reply