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.
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?