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

92
Vistas
Adding pasted image to form in JavaScript

I have a simple form which allows you to paste an image. The image is previewed using JavaScript.

In the snippet the paste area is a textarea for testing purposes.

After the image is pasted, it’s not yet in the form’s data. Is there a way of doing this so that the image can be uploaded on submit?

var previews = document.querySelector('div#previews');
var form = document.querySelector('form#data');
form.elements['stuff'].onpaste = function (event) {
    files = event.clipboardData.files;
    var img = document.createElement('img');
    img.width = '200';
    previews.appendChild(img);
    var reader = new FileReader();
    reader.onload = () => { 
        img.src = reader.result; 
    };
    reader.readAsDataURL(files[0])
};
textarea, input, button {
  display: block;
 }
<form id="data">
    <textarea name="stuff"></textarea>
    <input type="file" name="photo">
  <button name="doit">OK</button>
</form>
<div id="previews">
    
</div>

about 4 years ago · Santiago Gelvez
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