Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda