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.

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?

If we select unallowed file type of more than one file it won't works

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.