title: Validate input type="file" field using javascript
body: <p>I have a form in which the user first select if they want to upload any file. If yes then 3 upload box are displayed to them. </p>
  
  <p>On click of submit there is a JavaScript function which checks for any empty fields. In this function, if the option to upload file is selected, then I am checking if the input type="file" is empty.</p>
  
  <p>The error I am facing is that even after the user select a file for upload, the error message to upload a file is still displayed. </p>
  
  <p>Here is my HTML code:</p>
  
  <pre><code>&lt;!-- 3rd Fieldset STARTS --&gt;
  &lt;fieldset class="fieldSetSpace"&gt;
      &lt;legend class="legendText"&gt;&amp;nbsp; Upload Documents &amp;nbsp;&lt;/legend&gt;
  
      &lt;span id="yes"&gt;&lt;input type="radio" name="rdoUploadDocu" id="rdoUploadDocuYes" tabindex="23" value="yes" onClick="javascript: showUploadDiv();" /&gt;&lt;/span&gt;
      &amp;nbsp;Yes I have A Documents To Upload
  
      &lt;div id="divUploadDoc" style="display:none;"&gt;
          &lt;span class="contact_table"&gt;Upload Document 1 &lt;/span&gt;
  
          &lt;input type="file" name="files[]" id="file1" class="txtCoName" /&gt;
  
          &lt;span class="contact_table"&gt;Upload Document 2&lt;/span&gt;
  
          &lt;input type="file" name="files[]" id="file2" class="txtCoName" /&gt;
  
          &lt;span class="contact_table"&gt;Upload Document 3&lt;/span&gt;
  
          &lt;input type="file" name="files[]" id="file3" class="txtCoName" /&gt;
      &lt;/div&gt;
      &lt;?php echo $errorResumeUpload; ?&gt;
      &lt;br /&gt;
      &lt;span id="no"&gt;&lt;input type="radio" name="rdoUploadDocu" id="rdoUploadDocuNo" value="no" tabindex="24" onClick="javascript: hideUploadDiv();" /&gt;&lt;/span&gt;
      &amp;nbsp;No I do not have A Documents To Upload
  
      &lt;div id="divUploadCheckError" class="divError"&gt;&lt;/div&gt;
  
  &lt;/fieldset&gt;         
  &lt;!-- 3rd Fieldset ENDS --&gt;
  </code></pre>
  
  <p>Here is my JS function:</p>
  
  <pre><code>else if (document.getElementById('rdoUploadDocuYes').checked) 
  {       
      var upload1 =  document.getElementById('file1').value;
      var upload2 =  document.getElementById('file2').value;
      var upload3 =  document.getElementById('file3').value;
  
      alert( upload1 );
      alert( upload2 );
      alert( upload3 );
  
      if( ( upload1 == '' ) || ( upload2 == '' ) || ( upload3 == '' ) )
      {
          var objErrDiv = document.getElementById('divUploadCheckError');
          objErrDiv.innerHTML= 'Please upload at least one documents ';
          objErrDiv.style.padding='4px 4px';
          objErrDiv.style.visibility='visible';
          objErrDiv.style.margin='10px 0px 2px 0px';
          return false;
      }
      else
      {
          return false;
      }
  }
  </code></pre>
  
  <p>Any help will be appreciated.</p>