Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda