Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
evento de archivo de entrada onchange no funciona cuando el botón hace clic en el archivo de entrada

Disparo el archivo de entrada a través de la función JS de esta manera:

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

Este control tiene un evento onchange para validar el archivo:

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

El evento se activa correctamente pero cuando obtengo el archivo de entrada por Id no contiene el archivo:

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

Si hago lo mismo a través del archivo de entrada (cambiando estilo = "mostrar: ninguno") funciona como se esperaba.

¿Cómo puedo resolver este problema? ¿Que hice mal?

¡Gracias!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar el parámetro del evento onchange para acceder al objeto de archivos en el cambio

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!