I'm using:
<input type='file' name='pac1[]' multiple>
How do I javascript validate that there is at least one file selected?
When using:
<input type='file' name='pac1'>
I have no problem validating a single non-array entry.
You can use:
<input id="upload" type='file' name='pac1[]' multiple>
And JS:
if(document.getElementById("upload").files.length < 1)
{
alert("No file selected");
return false;
}
Bind change
event on input type='file'
element using addEventListener
INPUTElement.files.length
will return number of files selected.
document.querySelector('[name="pac1[]"]').addEventListener('change', function() {
alert(this.files.length);
});
<input type='file' name='pac1[]' multiple>
this.files.length
?