With a quick glance, I’m not seeing the error you’re mentioning, but you do seem to have a pretty big problem. You can’t have more than one element with #preview, or more than one element with #image. IDs are only supposed to exist once on a page, hence why getElementById might not be working as you think it should. You probably want to change those to classes and use getElementsByClassName.
Also, I would use somewhat more specific names than ‘image’ and ‘preview’. If you’re going to put this on a page with more content, those are pretty generic class names and could apply to just about anything.
Viewing 2 posts - 1 through 2 (of 2 total)