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

110
Vistas
javascript addEventListener will run more than once after several clicking

Click button will trigger setup function and add change event to input file, after choosing file , it will upload. The question is that it will run multiple times based on uploading times. I tried to reset the input file value after uploading , and still it will run twice in second times. How to fix this problem, I don't want to refresh page, and also I want it only run one time every click.

html code below

<input onclick='setup()' value='btn' type='button' class='btn btn-info'>
<form id='formid' method='POST' enctype='multipart/form-data'>
     <input accept='image/*' id='fileid' type='file' name='my_file' onsubmit='return false' />
     <input  type='submit' value='Submit' />
</form>

js code below

function setup(key) {
    document.getElementById('fileid').click();
    document.getElementById('fileid').addEventListener('change', submitForm);
    function submitForm() {
        var data = new FormData();
        data.append('my_file', $('#fileid').prop('files')[0]);
        $.ajax({
        url: 'ImageUpload.php',
        type: 'POST',               
        processData: false,
        contentType: false,
        data: data,
        success: function(data) {},
        error: function (error) {}
            });
        }
}
about 4 years ago · Juan Pablo Isaza
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