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

421
Visualizações
Getting the file size of a file in javascript
<input id="archivo" name="archivo" type="file">

So my field of type file is called archivo which parent is formIncidencia, so what i'm doing to find it is:

$('#formIncidencia').find("[id='archivo']");

This works fine but when i'm trying to do:

 $('#formIncidencia').find("[id='archivo']").files[0].size; 

it's not working like that, and i'm uploading a file so don't know what it's happening..

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You forgot to take the first element returned by jQuery's find:

$('button').click(() => console.log($('#formIncidencia').find("[id='archivo']")[0].files[0].size));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="formIncidencia">
<input id="archivo" name="archivo" type="file">
</form>

<button>Log file size</button>

I guess you should just use a single selector to achieve this:

$('button').click(() => console.log($('#formIncidencia > #archivo')[0].files[0].size));
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id="formIncidencia">
<input id="archivo" name="archivo" type="file">
</form>

<button>Log file size</button>

Also, if your page respects the HTML spec, it should not have more than one element with archivo as the id so even #formIncidencia would be superfluous.

about 4 years ago · Juan Pablo Isaza Relatório

0

Using $('#formIncidencia').find("[id='archivo']") will return an array of matches even if you only have 1 input field. So you would have to change it to $('#formIncidencia').find("[id='archivo']")[0].files[0].size;.

about 4 years ago · Juan Pablo Isaza Relatório

0

try the following:

$('#formIncidencia').find('change', function() {

  //this.files[0].size gets the size of your file.
  alert(this.files[0].size);

});
about 4 years ago · Juan Pablo Isaza 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