The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript TypeError: document.getElementById(…)

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #191762

    On my JavaScript function previewImage I am trying to make the document.getElementById pick my row id up.

    Because on my addImage() function I have a segment

    Where the two Id id=”uploadPreview[‘ + image_row + ‘]” & id=”uploadImage[‘ + image_row + ‘]” should work with my previewImage().


    TypeError: document.getElementById(…) is null

    I cannot getElementById to work with the image_row.

    Codepen Sample “”


    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.