I am checking the file size and extension of a file before it is uploaded, and (for the most part) the code is running correctly. However, I am unable to remove the disabled attribute from the submit button if the file has the correct extension and is under 2MB. I feel as if there is something minor I am not seeing or forgetting. I would appreciate any help or tips.
Thanks,
-Kyle
Here is my code:
<p>Select a logo to upload</p>
<input type="file" id="uploadFile" class="upload" name="upfile"><br>
<input type="submit" id="uploadSubmit" value="Upload Image" disabled="disabled">
document.getElementById("uploadFile").addEventListener("change", checkFile, true);
function checkFile(e) {
var files = e.target.files;
for (var i = 0, file; file = files[i]; i++) {
var fileName = file.name;
var fileExt = fileName.split(".")[fileName.split(".").length - 1].toLowerCase();
var fileSize = document.getElementById("uploadFile").files[0].size;
var fileSizeMB = (file.size / 2097152).toFixed(2);
if (!(fileExt === "jpg" || fileExt === "eps" || fileExt === "tif" || fileExt === "tiff") || fileSize > 2097152) {
alert("There is an error with the file you selected. Please check the file size and/or the file type.");
} else {
$("#uploadSubmit").prop("disabled", false);
}
}
};