Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
How to upload 1 image + convert to base64 + display the same image with the same ID multiple times on the same HTML page with javascript?

It works well but only display the image one time... Thank you for your help

<input type="file" id="file-upload" class="upload-file bg-highlight shadow-s rounded-s " accept="image/*">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This could work as expected. Choose an image file and use FileReader to read image data.

document.getElementById('file-upload').addEventListener('change', e => {
const file = e.target.files[0];
const reader = new FileReader();
reader.addEventListener("load", function () {
    document.querySelectorAll('#image-data').forEach(i => i.src = reader.result);
});
if (file) {
    reader.readAsDataURL(file);
}
});
#image-data { width: 100px; height: 100px; }
<input type="file" id="file-upload" class="upload-file bg-highlight shadow-s rounded-s " accept="image/*">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

<img id="image-data" src="images/empty.png" class="img-fluid">

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!