isme
isme

Reputation: 190

addEventListener and attachevent type mismatch on IE11.0

Hi i accounter some problem with javascript on DOM.

I am using IE v11.0

I have a page consist of a few buttons, upload file and select box

upon loading, I accounter an error stated that Type mismatch.

i have a select box which act nothing but just a few option

<select id="myOption">
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
</select>

I have a java script which wil do something to an image if it select

<script>
    document.getElementById("myOption").attachEvent("onclick", imgChange());

    function imgChange(){
        // declare some variaables and change some element.

     }
</script>

Upon running, in the console, it will say type mismatch on

document.getElementById("myOption").attachEvent("onclick", imgChange());

I have change it to "addEventListener("onclick, imgChange());" however it does the same as well..

Help be much appreciated. Thanks

Upvotes: 0

Views: 518

Answers (1)

Super User
Super User

Reputation: 9642

Just change your script like below:

<script>
    document.getElementById("myOption").attachEvent("click", imgChange);

    function imgChange(){
    // declare some variables and change some element.

    }
</script>

Upvotes: 1

Related Questions