I have a html file input control for selecting file. When form is submitted I need to check if user actually selected something, if not show an alert and do not submit.
Following is the HTML code
<form name="" id="" ....>
<input type="file" name="zip_file_import" id="zip_file_import" />
<input type="button" value="Upload" onclick="formSubmit()" />
</form>
JavaScript is as follows
function formSubmit() {
if(document.getElementById("zip_file_import").value='') {
alert("Please select a zip file");
return false;
}
document.getElementById(“import_form”).submit();
document.body.style.cursor = “wait”;
}
This code does not work and the form submits even no file is selected by the user. Any idea what could be wrong?
Thank you