How do I know if he clicked open? [INPUT]

Asked

Viewed 158 times

-3

Good people I was wondering if there is any way to know if the user clicked on open there, because I wanted to perform an action right after that. My goal is to execute an ajax request when the guy has clicked open... I have a code here , but it does not adapt this. inserir a descrição da imagem aqui

1 answer

-3


Just create a listener to run some code when the input is clicked and that will open the window to select a file:

$("#file").on("click", function(){
   alert("vai abrir a janela de selecionar arquivo");
   // insira aqui o código que deseja executar
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="file" />

  • But this will work even if he does not choose any file, just clicking to select the file, will already trigger the event. What if the user clicks cancel and does not select anything? He wants the action to fire only after clicking open, then the value country input would no longer be empty, and could indicate that the file was selected, and also a check to see if it was changed and trigger another event. For me this answer does not answer the question of AP.

  • His question is almost the same as Soen’s How to determine if user Selected a file for file upload?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.