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

126
Visualizações
How to get files count if the input file type was in a modal?

I have an input type file but it's in a modal, how to get its files count? I have tried below, but I can't get the value, what did I do wrong?

for (var index = 0; index < document.getElementById('supporting_files').files.length; 
  index++) {
     params.append("supporting_files", 
     document.getElementById('supporting_files').files[index]);
}

snippet

<div class="modal-dialog modal-dialog-centered modal-dialog- scrollable">
    <div class="modal-content">
    <div class="modal-body">
    <form id="form-pickupModal" method="post" autocomplete="off" 
       novalidate="novalidate">
        <div class="row">
           <div class="col">
              <div class="form-group">
                <label class="form-label" for="supporting_files">Supporting files</label>
                <input class="form-control" id="supporting_files" name="supporting_files" type="file" accept=".jpg,.jpeg,.png,.xlsx,.xls,.doc,.docx,.pdf" value="" multiple>
             </div>
          </div>
         </div>
      </div>
   </div>
</div>

As you see from the above snippet, it's a modal with an input file type there, I don't have an idea on how to get it's value.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can use length property of FileList to get number of files selected. and use item method to get particular file via index.

function grabFiles() {
    console.log('Selected few files');
    const files = document.getElementById('all_files').files;
    //Note that this files variable is of type FileList and it has a property length
    console.log('Number of file selected is: ', files.length);
    for (let i = 0; i < files.length; i++) {
        console.log(files.item(i));
    }
}
<input type="file" id="all_files" multiple onchange="grabFiles()" />

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