title: How to remove image input with required field by using javascript
body: <p>I did a script that check the image width and remove the image if the width is lesser than certain amount.</p>
  
  <p>The image field is required and after I removed it, it still passed the file validation.</p>
  
  <p>sample: <a href="http://jsfiddle.net/AUQYv/3/" rel="nofollow">http://jsfiddle.net/AUQYv/3/</a></p>
  
  <pre><code>&lt;form action=""&gt;
      &lt;input type="file" id="file" required /&gt;
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Javascript</p>
  
  <pre><code>var _URL = window.URL || window.webkitURL;
  
  $("#file").change(function (e) {
      var file, img;
  
  
      if ((file = this.files[0])) {
          img = new Image();
          img.onload = function () {
              if(this.width&lt;490||this.height&lt;175){
              $("#file").val("").change();
              }
          };
          img.onerror = function () {
              alert("not a valid file: " + file.type);
          };
          img.src = _URL.createObjectURL(file);
  
  
      }
  
  });
  </code></pre>