Vahid Najafi
Vahid Najafi

Reputation: 5263

Validate only first upload input with jQuery

I have a form with two upload input.

<form action="http://localhost/royalshop/administrator/submit_product" method="post" accept-charset="utf-8" id="myform" enctype="multipart/form-data">  
  <div class="productpicstables">
    <input type="file" name="file1" />
  </div>
  <div class="productpicstables">
    <input type="file" name="file2" />
  </div>
</form>

I want to validate just the first one with jQuery. How can I do this?

It should be required and better to have size of 512*512.

Thanks.

Upvotes: 0

Views: 47

Answers (1)

Mushahid Khan
Mushahid Khan

Reputation: 2834

use the same name:

$('input[type="file"]').each(function() {
var $this = $(this);
if ($this.val() == '') { 
    Response('- Upload file not selected!', true);
    $this.addClass('Error').fadeOut().fadeIn();
    return false;
} else {
    $this.removeClass('Error');
}

});

Upvotes: 2

Related Questions