Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files input change event fires only once

I've made a small script using some of the HTML5 files features, which allows you to select one or more files, and each time it will write the name of the file(s). Everything works as it should, only the event to detect the value change of the files input fire only once, so how can I make it fire every change and not only on the first change?

By the way, here is what I made: http://tamir.netspot.co.il/html5/files/

like image 931
Cokegod Avatar asked Aug 24 '11 17:08

Cokegod


People also ask

How do I change the default input type file?

You can't. The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.

How can you tell if a file is canceled and clicked on input?

The property value id=”theFile” is used to link the JavaScript code to it using getElementById() method. The property value onclick=”initialize()” is used to specify the function call when the user has clicked on the input.

How do I upload an HTML file?

The <input type="file"> defines a file-select field and a "Browse" button for file uploads. To define a file-select field that allows multiple files to be selected, add the multiple attribute. Tip: Always add the <label> tag for best accessibility practices!


1 Answers

If you want to upload twice, clear file input value

$('input[type="file"]').val(null);

jsfiddle test

like image 107
fundon Avatar answered Oct 10 '22 22:10

fundon