Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i use javascript to validate one file upload and its work good but how i use this javascript for two File Upload.

This is code:-
JavaScript
$(document).ready(function () {
            $("form").submit(function (e) {
                var form = this;
                e.preventDefault(); //Stop the submit for now
                //Replace with your selector to find the file input in your form
                var fileInput = $(this).find("#File_ar")[0],
                    file = fileInput.files && fileInput.files[0];

                console.log(file)
                if (file) {
                    var img = new Image();

                    img.src = window.URL.createObjectURL(file);

                    img.onload = function () {
                        var width = img.naturalWidth,
                            height = img.naturalHeight;

                        window.URL.revokeObjectURL(img.src);

                        if (width == 1024 && height == 358) {
                           form.submit(); 
                        }
                        else
                        {
                            alert('Image must be 1024 * 158');
                        }
                    };
                }
            });
        });


and this is two input in view :-
HTML
<input class="form-control" data-val="true" data-val-required="This field is required" id="File_ar" name="File_ar" type="file" value="">

<input class="form-control" data-val="true" data-val-required="This field is required" id="File_en" name="File_en" type="file" value="">


What I have tried:

i Try to use File_en Input With File_ar in the same script, How i do this?
Posted
Updated 19-Jun-17 9:02am

1 solution

I think you need something like this:
JavaScript
var fileInput = $(this).find("#File_ar")[0],
  file = fileInput.files && fileInput.files[0];
var fileInput2 = $(this).find("#File_en")[0],
  file2 = fileInput.files && fileInput.files[0];
if (file) {...};
if (file2) {...};
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900