<p>If I have a </p>

<pre><code>&lt;input id="uploadFile" type="file" /&gt;
</code></pre>

<p>tag, and a submit button, how do I determine, in IE6 (and above) if a file has been selected by the user.</p>

<p>In FF, I just do:</p>

<pre><code>var selected = document.getElementById("uploadBox").files.length &gt; 0;
</code></pre>

<p>But that doesn't work in IE.</p>

[{'answer_id': 46242, 'author': 'Jason Bunting', 'author_id': 1790, 'author_profile': 'https://Stackoverflow.com/users/1790', 'pm_score': 8, 'selected': True, 'text': '<p>This works in IE (and FF, I believe):</p>\n\n<pre><code>if(document.getElementById("uploadBox").value != "") {\n   // you have a file\n}\n</code></pre>\n'}, {'answer_id': 22152474, 'author': 'Atiqur', 'author_id': 2804202, 'author_profile': 'https://Stackoverflow.com/users/2804202', 'pm_score': 3, 'selected': False, 'text': "<pre><code>var nme = document.getElementById(&quot;uploadFile&quot;);\nif(nme.value.length &lt; 4) {\n    alert('Must Select any of your photo for upload!');\n    nme.focus();\n    return false;\n}\n</code></pre>\n"}, {'answer_id': 42990754, 'author': 'Ashu', 'author_id': 1874707, 'author_profile': 'https://Stackoverflow.com/users/1874707', 'pm_score': 2, 'selected': False, 'text': '<pre><code>function validateAndUpload(input){\n    var URL = window.URL || window.webkitURL;\n    var file = input.files[0];\n\n    if (file) {\n        var image = new Image();\n\n        image.onload = function() {\n            if (this.width) {\n                 console.log(\'Image has width, I think it is real image\');\n                 //TODO: upload to backend\n            }\n        };\n\n        image.src = URL.createObjectURL(file);\n    }\n};\u200b\n\n&lt;input type="file" name="uploadPicture" accept="image/*" onChange="validateAndUpload(this);"/&gt;\n</code></pre>\n\n<p>Call this function on change .  </p>\n'}, {'answer_id': 50415093, 'author': 'Elion Limanaj', 'author_id': 9807638, 'author_profile': 'https://Stackoverflow.com/users/9807638', 'pm_score': 2, 'selected': False, 'text': '<p>You can use:</p>\n\n<pre><code>    var files = uploadFile.files;\n\n    if (files.length == 0) { console.log(true) } else { console.log(false) }\n    if (files[0] == undefined) { console.log(true) } else { console.log(false) }\n    if (files[0] == null) { console.log(true) } else { console.log(false) }\n</code></pre>\n\n<p>All three give the same result.</p>\n'}, {'answer_id': 74571436, 'author': 'sifr_dot_in', 'author_id': 2173890, 'author_profile': 'https://Stackoverflow.com/users/2173890', 'pm_score': 0, 'selected': False, 'text': "<p>The accepted answer is correct to check with &quot;ID&quot;</p>\n<p>But, those who are here to check file with <strong>class-name</strong>,</p>\n<p>here is the code:</p>\n<pre><code>var elements = document.getElementsByClassName('uploadFile_ClassName');\nfor (var i = 0; i &lt; elements.length; ++i) {\n    if(elements[i].value != &quot;&quot;) {\n        // file is selected here;\n    }\n}\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/46219', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/698/']