By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,384 Members | 671 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,384 IT Pros & Developers. It's quick & easy.

How i Validation Width and height multiple input image before save using jquey

P: 2
i have two input every input upload one image , and i write script to validation width and height for one input only and i don't know i use this script to validation two input.

this is html code:-

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

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

<input type="submit" name="" value="Save" ,="" class="btn btn-primary col-md-2">


and this is script i write it:-

Expand|Select|Wrap|Line Numbers
  1. $(document).ready(function () {
  2.             $("form").submit(function (e) {
  3.                 var form = this;
  4.                 e.preventDefault(); //Stop the submit for now
  5.                 //Replace with your selector to find the file input in your form
  6.                 var fileInput = $(this).find("File_ar")[0],
  7.                     file = fileInput.files && fileInput.files[0];
  8.  
  9.                 console.log(file)
  10.                 if (file) {
  11.                     var img = new Image();
  12.  
  13.                     img.src = window.URL.createObjectURL(file);
  14.  
  15.                     img.onload = function () {
  16.                         var width = img.naturalWidth,
  17.                             height = img.naturalHeight;
  18.  
  19.                         window.URL.revokeObjectURL(img.src);
  20.  
  21.                         if (width == 1024 && height == 358) {
  22.                            form.submit(); 
  23.                         }
  24.                         else
  25.                         {
  26.                             alert('image must be 1024*358');
  27.                         }
  28.                     };
  29.                 }
  30.             });
  31.         });
  32.  
Jun 18 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.