Reputation: 81
I have multiple files to upload in a PHP page. Two of them are required field in that. To check that validation I wrote a JS. In my JS, the file types 1 & 2 are required types. Here count
is the number of files to upload.
for (i = 1; i <= count; i++) {
if (file_type == 1 || file_type == 2) {
found1++;
}
}
When the value of found1
becomes 2
the form submission will done. But here a problem is that the required field '1' is uploaded twice the flag value become 2
and the form submission will done. My requirement is '1' & '2' must include in form submission. How to solve this?
Upvotes: 0
Views: 39
Reputation: 25882
This will work, but there should be better ways.
var file1Uploaded,file2Uploaded = false
for (i = 1; i <= count; i++) {
if (file_type == 1) {
file1Uploaded=true;
}
else if(file_type == 2){
file2Uploaded=true;
}
}
check
if(file1Uploaded && file2Uploaded){//submit form}
Upvotes: 1