SCRIPT438: Object doesn't support property or method IE

JavascriptInternet Explorer

Javascript Problem Overview


I have an option in my application where users can deactivate their profiles. Only admin can activate them again.

I have a class ActivateProfile with two methods

  • userExist(userName) that checks if user with that userName exists and his/her profile is deactivated
  • and activateAccountByUser(userName) that activate the profile of the user again

I call a JavaScript function on the click event of an input type button. This code works fine on Chrome and Mozilla, but on Internet Explorer I get this error:

> SCRIPT438: Object doesn't support property or method userExist

function activateProf() {        
   var userName=document.getElementById("userName").value;
    
   if (userName == "") {
      alert("Полето е задолжително");
   } else {
      alert(userName + "1");
      ActivateProfile.userExist(userName, { callback:function(exist) {
         if (userName) {
            ActivateProfile.activateAccountByUser(userName);
            alert("User is activated");
         } else {
            alert("User does not exist");
         }
      }});
   }
}

Here is the code for Activate profile class

 public void activateAccountByUser(String userName) {
    try {
        Connection c = DBComm.getInstance().getConnection();
        Statement s = c.createStatement();
        ResultSet set = s.executeQuery("select * from accounts where userName = '" + userName + "' and isauthorized='2'");
        
        if (set.next()) {
            Statement st = c.createStatement();
            st.executeUpdate("update accounts set isauthorized='1' where userName='" + userName                    + "' and isauthorized='2'");
        }
        s.close();
        c.close();
    } catch (Exception ex) {
        java.util.logging.Logger.getLogger(ActivateProfile.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public boolean userExist(String userName) throws SQLException {
    //true exist
    //false does not exist
    boolean existEmbg = false;

    try {
        Connection c = DBComm.getInstance().getConnection();
        Statement s = c.createStatement();
        ResultSet set = s.executeQuery("select * from accounts where userName = '" + userName + "' and isauthorized='2'");

        if (set.next()) {
            existEmbg = true;
        } else {
            existEmbg = false;
        }
        s.close();
        c.close();
    } catch (Exception ex) {
       java.util.logging.Logger.getLogger(ActivateProfile.class.getName()).log(Level.SEVERE, null, ex);
    }
    return existEmbg;
}

Javascript Solutions


Solution 1 - Javascript

After some days searching the Internet I found that this error usually occurs when an html element id has the same id as some variable in the javascript function. After changing the name of one of them my code was working fine.

Solution 2 - Javascript

This is a common problem in web applications which employ JavaScript namespacing. When this is the case, the problem 99.9% of the time is IE's inability to bind methods within the current namespace to the "this" keyword.

For example, if I have the JS namespace "StackOverflow" with the method "isAwesome". Normally, if you are within the "StackOverflow" namespace you can invoke the "isAwesome" method with the following syntax:

this.isAwesome();

Chrome, Firefox and Opera will happily accept this syntax. IE on the other hand, will not. Thus, the safest bet when using JS namespacing is to always prefix with the actual namespace. A la:

StackOverflow.isAwesome();

Solution 3 - Javascript

I have added var for all the variables in the corrosponding javascript. That solved the problem in IE.

Previous Code

billableStatus = 1 ;
var classStr = $(this).attr("id").split("_");  
date = currentWeekDates[classStr[2]]; // Required    
               
activityNameId = "initialRows_" + classStr[1] + "_projectActivityName";
activityId = $("#"+activityNameId).val();        

var projectNameId = "initialRows_" + classStr[1] + "_projectName" ;
projectName = $("#"+projectNameId).val();        

var timeshitEntryId = "initialRows_"+classStr[1]+"_"+classStr[2];     
timeshitEntry = $("#"+timeshitEntryId).val();   

New Code

var billableStatus = 1 ;
var classStr = $(this).attr("id").split("_");  
var date = currentWeekDates[classStr[2]]; // Required    
               
var activityNameId = "initialRows_" + classStr[1] + "_projectActivityName";
var activityId = $("#"+activityNameId).val();        

var projectNameId = "initialRows_" + classStr[1] + "_projectName" ;
var projectName = $("#"+projectNameId).val();        

var timeshitEntryId = "initialRows_"+classStr[1]+"_"+classStr[2];     
var timeshitEntry = $("#"+timeshitEntryId).val();   

Solution 4 - Javascript

My problem was having type="application/javascript" on the <script> tag for jQuery. IE8 does not like this! If your webpage is HTML5 you don't even need to declare the type, otherwise go with type="text/javascript" instead.

Solution 5 - Javascript

In my case I had code like this:

function.call(context, arg);

I got error message under IE

> TypeError: Object doesn't support property or method 'error'

In the body of 'function' I had "console.error" and it turns that console object is undefined when your console is closed. I have fixed this by checking if console and console.error are defined

Solution 6 - Javascript

I forgot to use var on my item variable

Incorrect code:

var itemCreateInfo = new SP.ListItemCreationInformation();
item = list.addItem(itemCreateInfo); 
item.set_item('Title', 'Haytham - Oil Eng'); 

Correct code:

var itemCreateInfo = new SP.ListItemCreationInformation();
var item = list.addItem(itemCreateInfo);  
item.set_item('Title', 'Haytham - Oil Eng');
    

Solution 7 - Javascript

Implement "use strict" in all script tags to find inconsistencies and fix potential unscoped variables!

Solution 8 - Javascript

We were able to solve this problem by adding in the Object.Assign polyfill to the files being imported and throwing the error. We would make it the highest import, that way it would be available to the other code to be called in the stack.

import "mdn-polyfills/Object.assign";

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill

Solution 9 - Javascript

This issue may be occurred due to improper jquery version. like 1.4 etc. where done method is not supported

Solution 10 - Javascript

I had the following

document.getElementById("search-button") != null

which worked fine in all browsers except ie8. ( I didnt check ie6 or ie7)

I changed it to

document.getElementById("searchBtn") != null

and updated the id attribute on the field in my html and it now works in ie8

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvikiforView Question on Stackoverflow
Solution 1 - JavascriptvikiforView Answer on Stackoverflow
Solution 2 - JavascriptpimView Answer on Stackoverflow
Solution 3 - JavascriptSuman-PHP4UView Answer on Stackoverflow
Solution 4 - JavascriptLynxyView Answer on Stackoverflow
Solution 5 - JavascriptosoitzaView Answer on Stackoverflow
Solution 6 - JavascriptJamil HaddadinView Answer on Stackoverflow
Solution 7 - JavascriptAlexView Answer on Stackoverflow
Solution 8 - JavascriptJustin E. SamuelsView Answer on Stackoverflow
Solution 9 - JavascriptSameerView Answer on Stackoverflow
Solution 10 - Javascriptblong824View Answer on Stackoverflow