You Can View User Feedback To This Tip
We all have learned that for performance reasons, we should perform field input validations using JavaScript if the user fills a form using a web client.
To validate the attachment
Requires Free Membership to View

function validateFileUpload () { for(i=0;i<document.forms[0].elements.length;++i) { var elem = document.forms[0].elements[i]; if (elem.type == "file") { alert ("Element-Value: " + elem.value); if (elem.value == "") { alert ("please attach you file"); return (""); } } } }
One of our friends, Lothar Mueller, submitted a code to validate the file upload control. What he checked was for an entry in that control. However, the code he wrote was not efficient. That way you would need to traverse through all the elements on the form. Here is a much simpler way. Go to File Upload Control properties by right clicking on it. Go to the HTML tab and specify an ID such as fileupload. Then use this ID in the validation of the onSubmit event.
if (document.forms[0].fileupload.value == ""){ alert ("please attach a file"); return false; }
Loks
This was first published in July 2001