SCRIPT438: Object doesn't support property or method IE
Asked Answered
D

10

63

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;
}
Dove answered 20/12, 2012 at 15:57 Comment(2)
accepted 2 of 16 question??Dullish
try to post your class ActivateProfile.Saad
D
90

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.

Dove answered 22/12, 2012 at 13:7 Comment(4)
Any hints on how to find the naming collision within a large codebase?Arnulfoarny
Solution for finding the collisions: #18434896, unix.stackexchange.com/questions/110645/… or #658851Arnulfoarny
I think the naming collision isn't the root cause. This happened to me because of a misplaced curly-brace on my javascript object. When I invoked the object it didn't exist because of my syntax error. So, I think, the browser did the next best thing and grabbed the DOM element of the same name. I fixed it by getting my javascript curly braces correct, not by renaming my Javascript object.Duna
@TomMcDonald in a sane world, the next best thing, would be to indicate the errorActor
M
8

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();
Micron answered 28/8, 2014 at 14:11 Comment(2)
I don't think that's correct... what is an instance where Chrome will bind to a "namespace" but IE will not?Linderman
Hi Jeremy! I'm not sure what you mean, can you elaborate?Micron
A
5

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();   
Andromache answered 4/3, 2013 at 12:33 Comment(1)
Localizing a variable with the var keyword solves the issue of naming a variable with the same name as an element's id--good call.Adjourn
B
2

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.

Baluster answered 15/11, 2013 at 21:37 Comment(0)
L
1

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

Lunar answered 27/1, 2016 at 12:59 Comment(0)
L
0

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');
Laural answered 15/5, 2015 at 11:24 Comment(0)
M
0

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

Mousseline answered 15/4, 2018 at 18:22 Comment(0)
S
0

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

Surge answered 26/11, 2018 at 23:18 Comment(0)
C
-1

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

Chinchin answered 18/11, 2013 at 11:11 Comment(0)
P
-1

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

Precaution answered 20/12, 2013 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.