Are there any JavaScript events in type=file
input? I.E. I would like to add an extra file input
upon selecting file in one of allready created:
Diagram:] :
file input 1 file input 2 file input 3
user selects some file in input 1
and JS adds new file input
file input 1 - somefile.txt file input 2 file input 3 *NEW* file input 4
I'm looking for meaningful event, on which i can bind addFileInput
method.
I also use jQuery 1.4 :]
Thank you
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.
The input event fires when the value of an <input> , <select> , or <textarea> element has been changed. The event also applies to elements with contenteditable enabled, and to any element when designMode is turned on. In the case of contenteditable and designMode , the event target is the editing host.
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!
You could add a new <input type="file"> whenever you finished uploading the previous files and hide the previous input. This way you keep adding a new input every time you want to add more files and prevent the previous input from being overwritten.
I believe onchange
should work.
Here is the event logged by Firebug when selecting a file with Firebug:
I guess change, is the one you are looking for:
$ ('#your_form_id input[type=file]').live ('change', function () { $(this).parent ().append ($('<input type="file" />')); })
you just have to adapt the selector and the previous code should work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With