"Object expected" error using jQuery only in IE8

24,203

Solution 1

The problem is that you haven't added jQuery into your code at all. Add the following inside the <head> tag:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>

That should fix your problem.

Solution 2

I had a similar issue to this before with IE8, if it's the same issue, it can't find the jquery library, check your path or test it with a cdn

Solution 3

I tried the following code in IE8, and it works just as expected. As suggested in other answers, I used the latest version of JQuery that is compatible with IE8 from the JQuery CDN. Don't use 2.x -- it does not work with older browsers. Also, make sure your change event code is located in a document.ready handler.

<html>
    <head>
        <title>IE8 Object Expected</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function(){
                $("#deviceProfileSelection").change(function(){
                    console.log("#deviceProfileSelection changed to " + $(this).find(":selected").text());
                });
            });
        </script>
    </head>
    <body>
        <form>
            <select id="deviceProfileSelection">
                <option value="">Select...</option>
                <option value="1">One</option>
                <option value="2">Two</option>
                <option value="3">Three</option>
            </select>
        </form>
    </body>
</html>

Solution 4

Check the following:

  1. Is jQuery included when this code is executed? (I'd do an alert on $ and see what you get)
  2. Make sure the deviceProfileSection element exists.
Share:
24,203
victorf
Author by

victorf

www.victorf.ch

Updated on March 17, 2020

Comments

  • victorf
    victorf about 4 years

    I'm getting an error only in IE (v8, I don't know if it happens in older IE versions, but it does not occur in Chrome or Firefox) which brings me the following message when I use IE dev tool's debbuger:

    Breaking on JSScript runtime error - Object Expected
    

    Here is my affected code:

    $('#deviceProfileSelection').change(function() { //affected line!!!!
    // rest of my code...
    });
    

    This element #deviceProfileSelection is defined as the following:

    <select id="deviceProfileSelection">
       <option value=""><?php echo getSysMessage("dropDownSelect")?></option>
       <!-- and other values...-->
    </select>
    

    I've already tried defining the .change listener into a $(document).ready(function () {}); but no success at all. Any other idea?

    EDIT

    I was trying to include a div using a PHP decision structure, where if a condition was true, it should print a div. But, actually it wasn't printing, I mean, it wasn't printing the opening tag 'div', only the closing tag 'div'.

    The browsers could interpret this error, but IE8, and this IE inability was causing the issue.

  • victorf
    victorf over 10 years
    No, surely it is already included. I can use other elements normally.
  • victorf
    victorf over 10 years
    OMG, it works perfectly! I was trying to include a div using a php decision structure where if a condition was true, it should print a div. But, actually it wasn't printing, I mean, it wasn't printing the opening tag 'div', only the closing tag 'div'.
  • victorf
    victorf over 10 years
    Chrome and Firefox ignore this "unopened" div and that's why I couldn't see the error.