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

224
Views
how to fill a div with an image the user uploads?

I am working on a rudimentary site that enables users to upload images to the server and download them from it. I want to add a "preview" feature that will allow the user to see its photo beforehand. Here is my code:

 <div class="container">
        <input type="file" class="title3" id="picker"/>
        <img src= this.input alt="IDK why, but I can't display that." class="title3">;

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

0

You can use JavaScript to dynamically update the image source of the img tag.

const img = document.getElementById('preview');
const input = document.getElementById('picker');
input.onchange = function(ev) {
  const file = ev.target.files[0]; // get the file
  const blobURL = URL.createObjectURL(file);
  img.src = blobURL;
}
<div class="container">
  <input type="file" class="title3" id="picker" />
  <img id="preview" alt="IDK why, but I can't display that." class="title3" width="200">
</div>

about 4 years ago · Juan Pablo Isaza Report

0

I updated the code.

const selectFile = evt => {
  const [file] = evt.target.files;
  if (file) {
    document.getElementById('preview').src = URL.createObjectURL(file);
  }
}
<div class="container">
  <input type="file" class="title3" id="picker" onchange="selectFile(event)" />
  <img id="preview" alt="IDK why, but I can't display that." class="image">;
</div>

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!