How to know if the file input has something?

1

Good morning, everyone? I'm very bad ...

People like me can know that the guy selected some pc file?

Type wanted to know this answer in true or false with jquery.

For example it appears there: [NO FILE SELECTED] Then when the guy selects something like I know he has selected?

    
asked by anonymous 31.12.2017 / 02:16

1 answer

0

Just do a check if the field has value. You can get the id of the field:

function checa(){
   var input_file = $("#file").val();
   
   if(input_file){ // retorna true se teve algum arquivo selecionado
      alert("arquivo selecionado");
   }else{
      alert("nenhum arquivo selecionado");
   }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="file" id="file" />
<br />
<input type="button" value="Verificar" onclick="checa()" />
  

This check is basic, it works with input type text also.   Just check if there is a value in the field.

    
31.12.2017 / 02:23