I want to validate my form having
<input type="file" id="file[]">
I want to submit form only when file is uploaded else throw an error message popup.
The problem is this that i have made the code to upload the multiple files. So ID attribute of <input type="file"> is array(file[]).
I have tried
document.getElementById('file').valuedocument.getElementById('file[]').valuedocument.getElementById('file[3]').value
But everytime it’s not working.
I have checked it via firebug, it is giving error
document.getElementById(...) // is null.
You cannot create multiple elements with same id. Instead of id use class=’fileInput’ and
Use
var fileArr = document.getElementByClassName(“fileInput”) ;
Then loop through the array and check whether all the file input is valid..