title: How to determining if a file has been selected in JavaScript?
body: <p>I'm using JavaScript to validate an uploading form, one of the conditions is to check if any file has been selected. I thought this would be simple, but I can't get it to work. Is this code invalid? The var file works with other conditions so it's not that</p>
  <pre><code>var file = document.getElementById('file');
  
  if(file.value ==&quot;&quot;) {
      alert(&quot;no file selected&quot;)
      return false;
  }
  
  &lt;input  name=&quot;uploaded&quot; type=&quot;file&quot; id=&quot;file&quot; /&gt;
  </code></pre>