0

Hi..

I want to reset the multiple file input field.
Actually my file input field is an array.

I used the following code and it works if the input field is not an array.

<script>
$(function() 
{
$('input[type=file]').change(function () 
    {
    var regex = new RegExp("(.*?)\.(jpg|jpeg|png|pdf)$");
    var f           =   this.files[0];
    $.each(this.files, function (index, file) 
    {
       fileName = file.name;

       fileName =fileName.toLowerCase();

        if(!(regex.test(fileName))) 
        {
            $(this).val('');

            alert('JPG/PNG/PDF files Only');
         }


        });

});
</script>     

     <form>
     <input type=file style="width:100%" id='filename' name='filename[]' multiple="multiple"  />
     </form>

Please help me to find a solution for this.

2
Contributors
3
Replies
7
Views
2 Years
Discussion Span
Last Post by minitauros
0

When do you want those fields to have their values reset? Because looking at your code, there doesn't seem to be a problem to me: if a selects an unallowed file type for uploading, he will get an alert and the field will be rest, right? Isn't that what you want?

0

You mean that when you have multiple file inputs and select a unallowed file for more than one of those inputs, you get only errors for one of them? Or do you not get any errors at all?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.