Manage Learn to apply best practices and optimize your operations.

Input validation for file attachments using JavaScript

A solution is to validate the value of the HTML input element instead.

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 of a file, however, it is a bit more difficult since the file isn't uploaded until the form is submitted. A solution is to validate the value of the HTML input element instead. The standard Notes file upload control generates an HTML input element (type = "file") which takes the absolute path of the file to be uploaded. The following code validates the contents of that element. It can be put into the onSubmit event of the form along with the rest of the field validation functions.

function validateFileUpload () {
  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;


Dig Deeper on Domino Resources - Part 5



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury