Hi.
I have a form with 2 fields and a file upload control.
I have validation for the first 2 fields in place. I want a validation that atleast one file is attached to the document before the document is saved. I dont know how to validate using java script (its a web application).
How do I achieve this.
Please help if any of you have an idea. I have searched the forum but could get the proper answer.
Subject: File Validations
Give the upload control an id ( tab in the FileUploadControl propertie box), then you can use following to check if it is empty:
function checkFields(){
el = document.getElementById('MyFileUploadID');
if(el.value == ""){
alert("No attachment");
el.focus()
return false;
}
return true;
}
Subject: File Upload Control Validation
Johann,
I have to agree with the others, your tip for how to check if the user has attached a file to a File Upload Control in a Domino web app is brilliant.
The document.getElementById() method is not documented in my O’Reilly JavaScript 1.2 book so maybe it’s a more recent addition to the language and by not specifying a JavaScript version in my code, maybe that is why I am able to make use of it. It may be an undocumented feature, but it works!
Thanks,
Ken
Subject: RE: File Upload Control Validation
getElementById is not supported on all browsers. I use this function instead for broader compatibility.
function GetObject ( idName ) {
if (document.layers) {
// Netscape 4
return document.layers[ idName ];
} else if (navigator.userAgent.indexOf('Opera') != -1) {
// Opera
return document.all[ idName ];
} else if (document.all && !document.getElementById) {
// Explorer 4
return document.all[ idName ];
} else if (document.getElementById) {
// Netscape 6 & Explorer 5
return document.getElementById( idName );
}
}
Subject: RE: File Validations
Good One
Subject: RE: File Validations
Thanks Johann for a wonderful help. It is working perfectly.
Thanks again.
Subject: File Validations - Thank you!
Thank you so much… it’s really help me too.