Validating File Uploads and Disappearing Uploads

Validating File Uploads and Disappearing Uploads

I want users to be able to submit up to 5 attachments via File Upload and I want to validate those attachments.

To do this, I have a Dropdown list called How many Attachments with 1 through 5
This dropdown list will either show or hide the appropriate number of file upload fields.
After they upload the files, and click Submit this On_Validate script runs:

if (input.How_many_Attachments  ==  "0")
{
    input.Attachment_1 = "";
    input.Attachment_2 = "";
    input.Attachment_3 = "";
    input.Attachment_4 = "";
    input.Attachment_5 = "";
}
if (input.How_many_Attachments  ==  "1")
{
    if ((input.Attachment_1  ==  "")  ||  (input.Attachment_1  ==  null))
    {
        input.How_many_Attachments = "0";
    }
    input.Attachment_2 = "";
    input.Attachment_3 = "";
    input.Attachment_4 = "";
    input.Attachment_5 = "";
}
if (input.How_many_Attachments  ==  "2")
{
    if ((((input.Attachment_1  ==  "")  ||  (input.Attachment_1  ==  null))  ||  (input.Attachment_2  ==  ""))  ||  (input.Attachment_2  ==  null))
    {
        alert "Missing Attachments: Adjust How many Attachments or Upload more attachments";
        cancel submit;
    }
    input.Attachment_3 = "";
    input.Attachment_4 = "";
    input.Attachment_5 = "";
}
if (input.How_many_Attachments  ==  "3")
{
    if ((((((input.Attachment_1  ==  "")  ||  (input.Attachment_1  ==  null))  ||  (input.Attachment_2  ==  ""))  ||  (input.Attachment_2  ==  null))  ||  (input.Attachment_3  ==  ""))  ||  (input.Attachment_3  ==  null))
    {
        alert "Missing Attachments: Adjust How many Attachments or Upload more attachments";
        cancel submit;
    }
    input.Attachment_4 = "";
    input.Attachment_5 = "";
}
if (input.How_many_Attachments  ==  "4")
{
    if ((((((((input.Attachment_1  ==  "")  ||  (input.Attachment_1  ==  null))  ||  (input.Attachment_2  ==  ""))  ||  (input.Attachment_2  ==  null))  ||  (input.Attachment_3  ==  ""))  ||  (input.Attachment_3  ==  null))  ||  (input.Attachment_4  ==  ""))  ||  (input.Attachment_4  ==  null))
    {
        alert "Missing Attachments: Adjust How many Attachments or Upload more attachments";
        cancel submit;
    }
    input.Attachment_5 = "";
}
if (input.How_many_Attachments  ==  "5")
{
    if ((((((((((input.Attachment_1  ==  "")  ||  (input.Attachment_1  ==  null))  ||  (input.Attachment_2  ==  ""))  ||  (input.Attachment_2  ==  null))  ||  (input.Attachment_3  ==  ""))  ||  (input.Attachment_3  ==  null))  ||  (input.Attachment_4  ==  ""))  ||  (input.Attachment_4  ==  null))  ||  (input.Attachment_5  ==  ""))  ||  (input.Attachment_5  ==  null))
    {
        alert "Missing Attachments: Adjust How many Attachments or Upload more attachments";
        cancel submit;
    }
}

But say I selected 2 attachments and I uploaded Attachment_1 but not Attachment_2, when the validate script encounters the empty or null Attachment_2 field and the alert triggers, the upload field Attachment_1 now says "Choose file, No File Chosen" but the blue [Remove] tag is still there. Attachment_1 actually is still holding the file, but the name isn't shown. And if I go ahead and upload an Attachment_2, the form will submit successfully with Attachment_1 and Attachment_2.


Is this a bug that can be fixed? When interrupted by a Validate script, shouldn't the upload field still show the name of the uploaded file it's holding?

Or is there something in my script that needs to change?

Thank you