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

307
Vistas
input file event onchange no work when button click input file

I fire input file via JS function like this:

function PujarFitxerGP() {
document.getElementById('FUFitxer').click();
};

This control have a onchange event to validate the file:

<input type="file" onchange="ValidateGP();return false;" ID="FUFitxer" style="display:none" />

Event is firing correctly but when I get the input file by Id not contains the file:

document.getElementById('FUFitxer').files[0].name; ------>UNDEFINED

If I do the same via input file (changing style="display:none") is working as expected.

How I can resolve this problem? What I did wrong?

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could use the onchange event's parameter to access the files object on change

function ValidateGP(e) {
  const file = e.target.files[0];
  console.log(file.name);
}

function PujarFitxerGP() {
  document.getElementById('FUFitxer').click();
};
#FUFitxer {
  display: none;
}
<input type="file" id="FUFitxer" onchange="ValidateGP(event)" />

<button onclick="PujarFitxerGP(event)">Click here!</button>

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