Validate all fields and display customized message error

This tip will allow you to check all fields in a form and display a customized error message for all of them.

This tip will allow you to check all fields in a form and display a customized error message for all of them.


For this example, the name of the form will be "F-General".

F-General contains :
- A radio button field which is named "G_Radio",
- A Editable Text Field which is named "G_Text"
- A Editable Text Field which is named "G_Mail"
- A Check list field which is named "G_CheckList"
- Two INPUT PASSWORD field which names are "G_Password" and "G_ConfirmPass"

The javascript must be verified that :
- G_Radio have a selection
- G_text contains a text
- G_Mail is a mail
- G_CheckList have a selection
- G_ConfirmPass = G_Password
- And that G_Password contains more than 6 characteres.

Part G_Radio :
function verifnullradio(namefield,messerror,messglobal)
{
 if (eval('document.forms[0].' + namefield))
 {
   checklist="no"
   radio = eval('document.forms[0].' + namefield);
   for (var i=0; i<radio.length;i++) {
        if (radio[i].checked) checklist="yes"
     }
   if (checklist=="no") {
       messglobal=messglobal+"n"+messerror;
       return messglobal;
   }
 }
 else {
    return messglobal
 }
}

Part G_Text :
function verifnull(namefield, messerror,messglobal)
{
 if (eval('document.forms[0].' + namefield))
 {
 Preciser_Text = eval('document.forms[0].' + namefield + '.value');
 if ( Preciser_Text == "" )
 {
 messglobal=messglobal+"n"+messerror;
 eval('document.forms[0].' + namefield + '.focus()');
 return messglobal;
 }
 else
 return messglobal;
 }
 else
 return messglobal
}

Part G_Mail :
function verifmail(namefield, messerror, messglobal) {
  if (eval('document.forms[0].' + namefield))
  {
 mail = eval('document.forms[0].' + namefield + '.value');
 if ( mail == "" )
 {
  messglobal=messglobal+"n"+messerror;
  eval('document.forms[0].' + namefield + '.focus()');
  return messglobal;
 } else {
      if
((mail.indexOf("@")>=0)&&(mail.indexOf(".")>=0)
&&(mail.substring(mail.lastIn
dexOf('.')).length>2)&&(mail.substring(mail.lastIndexOf('.')).length<5)) {
          return messglobal
       } else {
   messglobal=messglobal+"n"+messerror;
   eval('document.forms[0].' + namefield + '.focus()');
   return messglobal;
  }
 }
  } else {
   return messglobal;
  }
}

Part G_CheckList :
function verifnulllist(namefield, messerror,messglobal)
{
 if (eval('document.forms[0].' + namefield))
 {
 Preciser_Text = eval('document.forms[0].' + namefield +
'.options.selectedIndex');
 if ( Preciser_Text < 0 )
 {
 messglobal=messglobal+"n"+messerror;
 eval('document.forms[0].' + namefield + '.focus()');
 return messglobal;
 }
 else
 return messglobal;
 }
 else
 return messglobal
}

Part G_Password and G_ConfirmPass :
function validPassword(ttPassword, ttConfirmPassword, messglobal) {
 minlength=6;
 if (ttPassword.length <minlength && ttConfirmPassword.length <minlength )
{
  messglobal = messglobal + "n"+ "The password must contains more than 6
characteres." ;
 }
 else {
  if (ttPassword == "" && ttConfirmPassword != "") {
      messglobal = messglobal + "n"+  "The Password is null." ;
   ttConfirmPassword.value = "" ;
  }
  else {
   if (ttPassword != "" && ttConfirmPassword == ""){
    messglobal = messglobal + "n"+  "The confirmation is null" ;
    ttPassword.value = "" ;
   }
   else {
    if (ttPassword != "" && ttConfirmPassword != ""){
     if (ttPassword != ttConfirmPassword){
      messglobal = messglobal + "n"+  "The password and the confirmation
no
are the same." ;
      ttPassword.value = "" ;
      ttConfirmPassword.value = "" ;
     }
    }
   }
  }
 }
     return messglobal;
}

Script de validation :
var messglobal="";
function verifformgeneral() {
test="yes";

messglobal=verifnullradio("G_Radio", "Problem with G_Radio you must select
one button",messglobal);
if(!(messglobal=="")) test= "no";
messglobal=verifnull("G_Text", "Problem with G_Text you must insert
text",messglobal);
if(!(messglobal=="")) test= "no";
messglobal=verifmail("G_Mail", "Problem with G_Mail you must insert a valid
mail",messglobal);
if(!(messglobal=="")) test= "no";
messglobal=verifnulllist("G_CheckList", "Problem with G_CheckList you must
select one option",messglobal);
if(!(messglobal=="")) test= "no";
messaglobal=validPassword(document.forms[0].G_Password.value,documen
t.forms[0].G_ConfirmPass.value, messglobal);
if(!(messglobal=="")) test= "no";

if (test!="no"){
 return true
 }
else {
 alert("The next fields contains an error :n"+messglobal);
 messglobal="";
 return false;
}

}

Now you must put a Save action with the javascript code:
if (verifformgeneral()) document.forms[0].submit();
This was last published in September 2001

Dig Deeper on Lotus Notes Domino Administration Tools

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com'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 ...

SearchDataCenter

SearchContentManagement

Close