Dominic Oryema
Dominic Oryema

Reputation: 25

Unexpected Identifier javascript

I have this bit of code that is supposed to output test and then basically do stuff to a div tag. There is some sort of syntax error in it though that outputs" Uncaught SyntaxError: Unexpected identifier" code:

<script type="text/javascript">
    console.log("test");
    document.getElementById("file").onchange = function(){
        var div = getElementById("imageContainer");
        for each(var image in document.getElementById("file").files){
            div.appendChild("<img src=" + image + "/>");
        }
    };
</script>

Upvotes: 0

Views: 779

Answers (1)

Alex
Alex

Reputation: 35409

Change:

var div = getElementById("imageContainer");

To:

var div = document.getElementById("imageContainer");

getElementById is a member of the document object.

Upvotes: 3

Related Questions