Manage Learn to apply best practices and optimize your operations.

Validate Lotus Notes Domino fields using JavaScript

Learn how to use JavaScript to validate any type of Lotus Notes Domino field types, including text, buttons and checkboxes, courtesy of member Brad Nelson.

The following JavaScript function can be used to validate any Lotus Notes Domino field type -- for example, text, radio buttons, checkboxes, etc. One instance might be simply calling the JavaScript function from a submit button.

The Lotus Notes Domino agent expects the form to have a field called RFields, which is a hidden, multi-valued text field that lists which Domino fields need to be validated.

RFields needs to be in the following format: <RequiredFieldName1>~<Field Description1>, <RequiredFieldName2>~<Field Description2>, etc.

An example of an RFields field would look like this:
"FName~First Name" : "LName~Last Name" : "Company~Company Name."

The agent parses each entry in RFields and checks the 'RequiredFieldName' to see if it contains any data. If it does not, it adds 'FieldDescription' to a text string, which is eventually displayed with an 'alert.' Here is the JavaScript code to accomplish this: 

function CheckRequired() {
var rfields = new Array();
var fieldsplit = new Array();
temp = document.forms
rfields = temp.split(", ");
x = rfields.length
var msg = ""
var eles = document.forms
for (var i = 0; i <x; i++) { 
fieldsplit = rfields[i].split("~")
field = eles[fieldsplit[0]]
if( field.type == "select-one" ) {
if( (field.selectedIndex == -1) || 
(field.options[field.selectedIndex].text == "") ) 
msg = msg + fieldsplit[1] + "\n"  
if( field.type == "select-multiple" ) {
if( (field.selectedIndex == -1) || 
(field.options[field.selectedIndex].text == "") 
) msg = msg + fieldsplit[1] + "\n"

if( field.type == "text" ) {
y = field.value
if( y == "") msg = msg + fieldsplit[1] + "\n"
if( field.type == null ) {   // since radio button 
and checkbox fields are arrays of options,
 field.type returns null, so check field[0].type 
(the first // option of either the
 radio buttons or checkboxes
if( field[0].type == "radio" ) {
b = field.length
ok = false
for( var k = 0; k<b; k++) {
if ( field[k].checked ) ok = true
if( ok == false ) msg = msg + fieldsplit[1] + "\n"
if( field[0].type == "checkbox" ) {
b = field.length
ok = false
for( var k = 0; k<b; k++) {
if ( field[k].checked ) ok = true
if( ok == false ) msg = msg + fieldsplit[1] + "\n" 
}  // end for
if (msg != "") {
msg = "The following fields are required:\n\n" + msg

}  // end function

Do you have comments on this tip? Let us know.

This tip was submitted to the tip library by member Brad Nelson. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

Dig Deeper on JavaScript for Lotus Notes Domino

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.



  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...