Download onClick file without clicking a button

I use js to upload files to the server using this

<form name="form" action="" method="POST" enctype="multipart/form-data" style="float:left;">
   <input id="fileToUpload" type="file" name="fileToUpload" class="input">
   <button class="button" id="buttonUpload" onClick="return ajaxFileUpload();">Upload</button>
</form> 

Instead of clicking the "Download" button, can I just return ajaxFileUpload();after viewing the file and send it to the input?

I tried

<form name="form" action="" method="POST" enctype="multipart/form-data" style="float:left;">
    <input id="fileToUpload" type="file" name="fileToUpload" class="input" onClick="return ajaxFileUpload();">
</form> 

but it immediately returns ajaxFileUpload();when I click on file input. Is there a way to return it only after it has some input in it?

+3
source share
1 answer

try using the onChange event.

+5
source

Source: https://habr.com/ru/post/1757711/


All Articles