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.
Requires Free Membership to View
Register today to access targeted resources from our editorial writers and independent industry experts focused on Lotus Domino, Notes, Workplace and other related technologies.
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
[0].RFields.value;
rfields = temp.split(", ");
x = rfields.length
var msg = ""
var eles = document.forms
[0].elements
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
alert(msg)
}
} // end function
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com 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.
This was first published in August 2007