Solved

inputvalidation: blank fields

Posted on 2001-08-03
45
323 Views
Last Modified: 2013-12-18
hi,

i posted this question before.
now my needs are a bit different and the suggestions made before seem not to work.

question:
any idea how i can check if fields are empty when pressing save on the web. the save button is a picture with a hotspotrectangle incluging a formular.

best would be if a message would popup displaying each field separately which is blanc (but a user definable text, not the fieldname).

e.g. "please enter the amount" if thre field amount is empty.

if the way i go for it isn't good, please also let me know.


thanks
hreinart
0
Comment
Question by:hreinart
  • 21
  • 13
  • 6
  • +2
45 Comments
 
LVL 13

Expert Comment

by:CRAK
ID: 6349064
Use javascript:
(I assume you're using R5....)

In JS HEader:


function Validate(fld, lbl)
{
  frm = document.forms(0)
  f = frm(fld)
  t = v.type
  ValFlag = 0
  if (t.indexOf('select')>=0)
  {
    if (v.selectedIndex<0)
    {
      ValFlag = 1
    }
  }
  else
  {
    if (v.value=='')
    {
      ValFlag=1
    }
  }
  if (ValFlag==1)
  {
    ValLst = ValLst + '\"' + lbl + '\"\n'
    if (ValFocus=='')
    {
      ValFocus = fld
    }
  }
}

function ValidateForm()
{
  ValLst = ''
  ValFocus=''
  // modify as folowing lines needed:
  Validate('Field1', 'Fieldlabel 1')
  Validate('Field2', 'Fieldlabel 2')
  // end modify
  if (ValLst='')
  {
    alert('Please fill-out following fields:\n\n' + ValLst)
    frm=document.forms[0]
    frm[ValFocus].focus()
    return(0)
  }
  else
  {
    // allow submit
    return(1)
  }
}

function DocSubmit()
{
  ValChk=ValidateForm()
  if (ValChk==1)
  {
    document.forms[0].submit()
  }
}


Make the button call the javascript function "DocSubmit()"

0
 

Author Comment

by:hreinart
ID: 6350208
hi crack,

looks very interesting, thanks sofar.
where is the java script haeder?
should i paste it into the top of the form and mark it as html?

the button function is at the click event?

i'm using v5, but can't program.

i'll be able to try it on monday!


thanks again
hreinart
0
 

Author Comment

by:hreinart
ID: 6351554
hi crack,

i played a little bit with it.
found the java header an implemented the code.
the button script is in the click event.

when pressing the button on the web, a runtime error
occurs.
it points me to the beginning of the script to this line:
 t = v.type

???
any idea what happend?

thanks
hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6351924
f = frm(fld)
should be:
v = frm(fld)

or:

Every occurrance of "v" should be renamed "f" in that function.

I wrote the code originally in dutch, on another (off-line) machine, where v was short for "veld", which is "field". "f" Seemed to make things easier to understand.... if I had not made that silly typing error!

I had to retype the code anyway; why not translate where possible, I thought....
My apologies!  ;-))
0
 

Author Comment

by:hreinart
ID: 6355651
hi crack,

i found exactly one line where i could change it as you described.
attached you find the code as i use it now.

now no error occures but also nothing happens when pressing this button.

maybe the modification for the fileds is done wrong by ?
could you please give me an expample?
e.g. i use the files "description".


thanks
hreinart



// field validation
function Validate(fld, lbl)
{
 frm = document.forms(0)
 v = frm(fld)
 t = v.type
 ValFlag = 0
 if (t.indexOf('select')>=0)
 {
   if (v.selectedIndex<0)
   {
     ValFlag = 1
   }
 }
 else
 {
   if (v.value=='')
   {
     ValFlag=1
   }
 }
 if (ValFlag==1)
 {
   ValLst = ValLst + '\"' + lbl + '\"\n'
   if (ValFocus=='')
   {
     ValFocus = fld
   }
 }
}

function ValidateForm()
{
 ValLst = ''
 ValFocus=''
 // modify as folowing lines needed:
 Validate('Field1', 'description')
 Validate('Field2', 'Fieldlabel 2')
 // end modify
 if (ValLst='')
 {
   alert('Please fill-out following fields:\n\n' + ValLst)
   frm=document.forms[0]
   frm[ValFocus].focus()
   return(0)
 }
 else
 {
   // allow submit
   return(1)
 }
}

function DocSubmit()
{
 ValChk=ValidateForm()
 if (ValChk==1)
 {
   document.forms[0].submit()
 }
}
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6355874
Two questions:

Does the button calll the DocSubmit()-function?

Are your fields called Field1 and Field2?

In the ValidateForm()-function you should identify the fieldnames and their labels: every field on a separate line. Add additional ones if neccessary.

Example:
Fieldlable: "Please enter your name: "
Fieldname: "Name"

Add/modify a line like:
Validate('Name', 'Your name')

0
 

Author Comment

by:hreinart
ID: 6358448
hi crack,

i tried it again, no chance.
here are the answers:
Does the button calll the DocSubmit()-function?
as far as i can see, yes.
inside the click event it runs the java script:
"DocSubmit()"


Are your fields called Field1 and Field2?
no.
names are like: description, amount, month

In the ValidateForm()-function you should identify the fieldnames and their labels: every field on a
separate line. Add additional ones if neccessary.

Example:
Fieldlable: "Please enter your name: "
Fieldname: "Name"

Add/modify a line like:
Validate('Name', 'Your name')



question:
could you give me a complete new script with validating 2 fields named: decription and amount?
this would make it for me more easy to see where i might created an error.

i guess that it's 98% ready, it'll be a little stupid
thing i don't see (because i don't programm).


thanks
hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6358853
Got the bug:

Lookup following lines:
// end modify
if (ValLst='')

Add an exclamation mark as follows:
// end modify
if (ValLst!='')

As I said... I had to re-type my original code again...
....98% .... 99%.... 100% completed now, right?   ;-))
0
 

Author Comment

by:hreinart
ID: 6358865
hi crack,

i'll test it now.
...but could you give me the examples for the line with the fieldnames.
i'd like to see the 100% correct code which i would past e into your code.


thanks
hreinart
0
 

Author Comment

by:hreinart
ID: 6358879
hi crack,

i'll get an error:
obect needed in line 12 which is:

 t = v.type

(of the source code [view source code])

regards
hreinart
0
 

Author Comment

by:hreinart
ID: 6358886
hi crack,

please look at this, if it's ok:

// modify as folowing lines needed:
 Validate('description', 'enter description')
 // end modify
 if (ValLst!='')

-------------------------------
i couldn't find anything like this to modify in  the source:
Fieldlable: "Please enter your name: "
Fieldname: "Name"

where in the code should it be written?
is the the correct java script statement?

???
i'm confused, sorry.

hreinart

0
 

Author Comment

by:hreinart
ID: 6358892
hi crack,

i found this:

ValLst = ''
 ValFocus=''

should be the fields be included here?
...i'm just guessing, i have no knowledge about java script.


hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6359037
The lines ValLst = '' and ValFocus='' are meant to initialize variables. No need to change.

That error could have two caused. In either case a field is not available: you try to read the value of a non-existing field, or there are no fields at all (as in read-mode). Fields (and their labels) are defined at the call of the ValidateForm()-function.
Please be aware that javascript is case-sensitive. If you define a field in Notes as "test" and refer to in in javascript as "Test", in won't work....

The entire code:

// field validation
function Validate(fld, lbl)
{
frm = document.forms(0)
v = frm(fld)
t = v.type
ValFlag = 0
if (t.indexOf('select')>=0)
{
  if (v.selectedIndex<0)
  {
    ValFlag = 1
  }
}
else
{
  if (v.value=='')
  {
    ValFlag=1
  }
}
if (ValFlag==1)
{
  ValLst = ValLst + '\"' + lbl + '\"\n'
  if (ValFocus=='')
  {
    ValFocus = fld
  }
}
}

function ValidateForm()
{
ValLst = ''
ValFocus=''
//
//
// modify as folowing lines needed:
//
Validate('<FieldName1>', '<Field label 1>') // modify fieldname and label as required
Validate('<FieldName2>', '<Field label 2>') // modify fieldname and label as required
//
// Add or remove Validate-lines as indicated above as required.
//
// end modify
//
//
if (ValLst!='')
{
  alert('Please fill-out following fields:\n\n' + ValLst)
  frm=document.forms[0]
  frm[ValFocus].focus()
  return(0)
}
else
{
  // allow submit
  return(1)
}
}

function DocSubmit()
{
ValChk=ValidateForm()
if (ValChk==1)
{
  document.forms[0].submit()
}
}


... and have a submit-button or action call the javascript DocSubmit()-fuction.

Required changes (field name/lable) definitions are to be made in the ValidateForm-function.

I could send you a working demo if you leave your e-mail address....

0
 

Author Comment

by:hreinart
ID: 6359303
yes, that'd be very nice.
please send zipped to:

anrufbeantworter1@gmx.de

then i'll see what exaxtly to put in for fieldname & lable.


thanks
hreinart
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6359505
Why make it so complicate ?
Use the following code, and it will work fines.
It also check to white spaces, because when the user click  one time on the spacebar, he must still give us a blanc field.

Place the following function in the JS Header:

// A utility function that returns true if a string contains only whitespace characters.

function isblank(s) {
for (var i= 0; i < s.length; i ++) {
var c = s.charAt(i);
if (( c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}

Within the onBlur or wherever you want it to be, check for the field. E.g.,

if (isblank(document.forms[0].Fname.value)) {
alert("You must enter your first name");
}


Greets,
Sloeber
0
 

Author Comment

by:hreinart
ID: 6359611
hi sloeber,

code works fine, but....
... i'd like to check all fields on the form.

could you extend?


best regards
hreinart
0
 

Author Comment

by:hreinart
ID: 6359619
i'd like to check it by saving the document.
if i only check when the user lefts a field, i can't be sure that he clicked this field at all.
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6359790
Sloeber,
My code was somewhat more complicated as it had to work on SELECT-fields as well. Don't ask for checkboxes.... I didn't have any on the form  ;-)
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6359808
It's almost the same
You have a button on your form Submit
with as formula
@Command([FileSave]);
@Command([FileCloseWindow]);

Now, use the OnSubmit event
The onSubmit event occurs in a browser and the Notes client when the FileSave @command executes.To simulate submitting a document in a browser, follow FileSave with the FileClose @command. Return false from the onSubmit event to abort the save operation.

In the Onsubmit event
write
if (isblank(document.forms[0].Fname.value)) {
alert("You must enter your first name");
}
else if (isblank(document.forms[0].Lname.value)) {
alert("You must enter your Last name");
}
................

Greets,
Sloeber
0
 

Author Comment

by:hreinart
ID: 6359820
???
sorry i don't understand this.

could you explain it please a bit more?
better, please give ma an expample to check more that 3 fields.


thanks
hreinart
(will read your answer tomorrow)
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6359829
It's almost the same
You have a button on your form Submit
with as formula
@Command([FileSave]);
@Command([FileCloseWindow]);

Now, use the OnSubmit event
The onSubmit event occurs in a browser and the Notes client when the FileSave @command executes.To simulate submitting a document in a browser, follow FileSave with the FileClose @command. Return false from the onSubmit event to abort the save operation.

In the Onsubmit event
write
if (isblank(document.forms[0].Fname.value)) {
alert("You must enter your first name");
}
else if (isblank(document.forms[0].Lname.value)) {
alert("You must enter your Last name");
}
................

Greets,
Sloeber
0
 

Author Comment

by:hreinart
ID: 6359830
???
sorry i don't understand this.

could you explain it please a bit more?
better, please give ma an expample to check more that 3 fields.


thanks
hreinart
(will read your answer tomorrow)
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Expert Comment

by:sloeber
ID: 6359834
It's almost the same
You have a button on your form Submit
with as formula
@Command([FileSave]);
@Command([FileCloseWindow]);

Now, use the OnSubmit event
The onSubmit event occurs in a browser and the Notes client when the FileSave @command executes.To simulate submitting a document in a browser, follow FileSave with the FileClose @command. Return false from the onSubmit event to abort the save operation.

In the Onsubmit event
write
if (isblank(document.forms[0].Fname.value)) {
alert("You must enter your first name");
}
else if (isblank(document.forms[0].Lname.value)) {
alert("You must enter your Last name");
}
................

Greets,
Sloeber
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6360019
Sorry for the double postings, but there was something wrong with my browser.
Here's the final solution
It's a mix from Crack suggestions and mine.
Thanks to Crack.

function DocSubmit()
{
ValChk = ValidateForm()
if (ValChk == 1)
{
document.forms[0].submit()
}
}

function ValidateForm()
{
if (isblank(document.forms[0].Fname.value))
{
alert("You must enter your first name");
return(0);
}
else
{
if (isblank(document.forms[0].Lname.value))
 {
alert("You must enter your Last name");
return(0);
}
else
{
return(1);
}
}
}


function isblank(s) {
for (var i= 0; i < s.length; i ++) {
var c = s.charAt(i);
if (( c != ' ') && (c != '\n') && (c != '\t'))
return false;
}
return true;
}


Greets,
Sloeber
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6362907
Have you received the demo allright?
0
 

Author Comment

by:hreinart
ID: 6362919
hi sloeber,

looks nice, i'll try it out.
could you please give me an advise whre to put each function?

can i extend the if command to e.g. 20 fields to be prooved
if blanc?
are all kind if fields prooveable (even checkboxes etc.)?


thanks
hreinart
0
 
LVL 4

Expert Comment

by:sloeber
ID: 6362961
Just put the functions in the JS Header.
You can check as much fields as you want.
No, I don't think that it works for Checkboxes.
For checkboxes you must use other methods.
document.forms[0].Fname.value is only for normal editable fields.
For checkboxes you must use something as selectedindex or so (there you must verify each possible value, to look of it's selected or not).
Crak used something in his answer.

I can find it out for you, but I've a meeting know and I don't know how long it will takes.

Greets,
Sloeber
0
 

Author Comment

by:hreinart
ID: 6363013
hi sloeber,

i tried in the meantime your previous suggestion:
In the Onsubmit event
write
if (isblank(document.forms[0].Fname.value)) {
alert("You must enter your first name");
}
else if (isblank(document.forms[0].Lname.value)) {
alert("You must enter your Last name");
}


generally it works fine, but....
1) after the error message appears, i see just a blanc page with "form processed". the form shouldn't be cleared so that the user can input the needed data

2) the filed category which is a dialog list field is prompted with an error even if one element is selected.
any idea?

i'll test your new suggestion now.


thanks
hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6363026
For the both of you: checkboxes

flg = false
d = document.forms[0]
for (i=0; i<d.elements.length; i++)  // cycle through ALL fields
{
  if (d.elements[i].name=='Box')  // take action if the requested field is found
  {
    if (d.elements[i].checked)
    {
      flg=true // set flag if checked (else leave flag unchanged)
    }
  }
}
alert(flg) // true = checked, false = unchecked


Checkboxes constist of different "fields" for each box, all sharing the same name. This comes from a different demo of mine - not compatible with the other code yet, but easy to adapt. My checkbox field here was "Box" (hardcoded).

Enjoy!
0
 

Author Comment

by:hreinart
ID: 6363106
hi sloeber,

i tested now the new version from you (the mix with crack).
more than 3 fields are testable, that's fine.
if a field is empty, the form/screen will stay until all needed data is entered.

the submit button now includes the following statement:
DocSubmit()
action="http://160.58.125.114/open.nsf/frame-open?OpenFrameset"

as far as i can judge it, your java script also saves the document if the fields aren't blanc. that's nice.

only the checkbox, dialog list etc. fields are not checked.
if you have a chance to find it out it'd be nice.

i'll be also in a mmeting and might read your answer tomorrow.



thanks sofar
hreinart
0
 

Author Comment

by:hreinart
ID: 6364322
hi crack,

i tested your database which you sent me by mail.
thanks a lot.

it's working...but the error i get referres to the kind of field being investigated.
if it is e.g. a textfield or dialog list field, it runs fine. if it is a checkbox or e.g. radiobutton field, i get the error. probably similar to the comment of sloeber.

i tested this out.

one thing i found out is that if rubbish is entered in a date field the form is not saved, but accepted.
no message is upcomming saying "enter a valid input".
i tried to use a input validation formular like:

@If(date< [01.01.1900]; @Success; @Failure("Please enter a valite date."))

but nothing happens by saving the document (just that it's not saved at all because of the entry e.g. "hello").
might be nice to validate this with javascript in the on blur event. in combination of the existing validation it could be perfect
...but i don't know the code...


bets regards
hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6367769
That's where the real "fun" starts!
Some servers need D-M-Y notation, others need M/D/Y....
I must admit that a generic piece of JS to validate that as well could be very usefull; inclusing radiobuttons, checkboxes and other field types... including conditional validations of course.
Haven't got anything suitable ready yet. Will work on it, but can't promise any results: I'm getting quite busy again!
0
 

Author Comment

by:hreinart
ID: 6383113
ok, i'll wait.

thanks sofar.
hreinart
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6435319
Still working on it.... but not a lot of progress yet!
Perhaps (if you really need it), this URL can help:

http://www.codestore.net/A55692/store.nsf/area/9BAA0CE3785D789E8625695900334995?OpenDocument

(Doesn't mean I'm giving up yet.... ;-)) )
0
 

Author Comment

by:hreinart
ID: 6435677
i'll have a look at it and time to wait for your progress (which was very good sofar!).

thanks
hreinart
0
 
LVL 13

Accepted Solution

by:
CRAK earned 100 total points
ID: 6652433
So here I am again.... finally!
I got a bit busier that I thought....

I made a new start writing the code. This one replaces my previous attempts.

I start off using a shared field, "$jsVal$" (text, CfD)which can be placed on all forms that need JS validation. It contains a few functions to pass server information to the client (int. date format, date- and numerical separators) and loads an external JS library. You'll need to change the path (jsRef) in the code:

REM "Provides Domino-computed information to javascript";
REM "Loads JS input validation routines";
REM ;
REM " Add field value (or formula) to $$HTMLHead";
REM "This way JS validation is R4.5 compatibel";
REM ;
REM "Available JS-functions:";
REM "     decimalSeparator()";
REM "     dateFormat()";
REM "     dateSeparator()";

REM "Ajust this reference to the external JS library containing validation routines here:";
JSref := "/myJsLib.nsf/libraryView/JSvalidation.js";

REM "Please refer to this JS library for additional info";


NumSep := @ReplaceSubstring(@Text(3/2); "1":"5"; "");
DtFmt := @ReplaceSubstring(@Text(@Date(2001; 5; 9)); "9":"5":"1":"2":"0"; "DD":"MM":"YYYY":"");
DtSep := @Unique(@Explode(@ReplaceSubstring(@Text(@Date(2001; 5; 9)); "9":"5":"1":"2":"0"; "x":"x":"x":""); "x"));
CR := @NewLine;

REM "Add a reference to the external JS validation library";
"[<Script Language=\"Javascript\" Src=\"" + JSref + "\"></Script>]" + CR +

"[<Script Language=\"Javascript\">" + CR +
CR +
"function decimalSeparator()" + CR +
"  {" + CR +
"  return(\'" + NumSep + "\')" + CR +
"  }" + CR +
CR +
"function dateFormat()" + CR +
"  {" + CR +
"  return(\'" + DtFmt + "\')" + CR +
"  }" + CR +
CR +
"function dateSeparator()" + CR +
"  {" + CR +
"  return(\'" + DtSep + "\')" + CR +
"  }" + CR +
CR +
"msg = \'\'" + CR +
"fldFocus = \'\'" + CR +
CR +
"</Script>]" + CR


Second: I have the code added (inherited) to $$HTMLHead on the form. This way the validation even works in R4.5 and $$HTMLHead's original code remains just as readable:
...lots of original code in $$HTMLHead... + $jsVal$

Third: make sure the JS library is available. It should contain following code (treated as HTML):

/*
      JS field validation module
      
      By:
            Ralph Kersten
            Company: E'liantie IT Professionals BV, The Hague, Netherlands
            23 nov. 2001


      This routine may be used, modified, and/or distributed freely for use in notes/domino environments,
      provided that both the company and the author mentioned above remain unchanged and the code
      is still functioning properly.
      Please add your name and additional comments when altering the code.

      
      This routine uses three additional JS functions, to be defined in either:
      -      JS header
      -      $$HTMLHead, or
      -      inherited by $$HTMLHead
      Preferred option for compatibility reasons: option 3, using a shared field "$jsVal$".

      The three functions are:
      -      decimalSeparator()
                  returning the decimal separator expected by your Domino server
      -      dateFormat()
                  returning the international date format used by the Domino server
      -      dateSeparator()
                  returning the date separator expected by your Domino server
      
      
      usage of this module:

      >      msg = ''
      >      fldFocus = ''
      >
      >      validate (<fieldname 1>, <field lable 1>, <switches 1>)
      >      validate (<fieldname 2>, <field lable 2>, <switches 2>)
      >      ...
      >      validate (<fieldname #>, <field lable #>, <switches #>)
      >
      >      if (msg != '')
      >      {
      >            alert(msg)
      >      }
      >      else
      >      {
      >            window.document.forms[0].submit(); // use $$Return to define further action
      >      }
            
      for a list of valid switches, please check the function "validate" below.
*/


function checkFocus(fld, fldIsArray)
{
      if (fldFocus == '')
      {
            fldFocus = fld.name
            if (fldIsArray == true)
            {
                  fld[0].focus()
            }
            else
            {
                  fld.focus()
            }
      }
}

function strTrim(str)
{
      return(str.split(' ').join(' '))
}

function compare(a, b)
{
      // used to provide a descending order to Array.sort()
      if (a > b)
      {
            return -1
      }
      else
      {
            return 1
      }
}

function returnSwitch(swList, swRequest)
{
      // returns a requested switch + value (if available)
      lst = swList.split(' ')
      sw = ''
      for (n=0; n<lst.length; n++)
      {
            if ((lst[n].substring(0,1) == swRequest) && (sw == ''))
            {
                  sw = lst[n]
            }
      }
      if ((sw != '') && (sw.length>1))
      {
            sw = sw.substring(0,1) + ' ' + sw.substring(1,sw.length)
      }
      return(sw)
}

function validate(fieldName, fieldLable, validationSwitches)
{
/*
      valid switches (use spaces as separator): E, N, L, U and/or V, depending on fieldtype:
      text / textarea / password / hidden:
            E = empty
            N = numeric (only in combination with E)
            L = min. value (add specification; only in combination with N)
            U = max. value (add specification; only in combination with N)
      date:
            E = empty
            D = valid date (only in combination with E)
      radio:
            E = empty
      checkbox:
            E = empty
            L = min. no. of options (add specification; only in combination with E)
            U = max. no. of options (add specification; only in combination with E)
      select:
            E = empty
            L = min. no. of options (multi-value only; only in combination with E)
            U = max. no. of options (multi-value only; only in combination with E)

      limitations:
            all switches are uppercase!
            in case of duplicate switches, only the first of a kind is evaluated
            illegal switches are ignored
            multivalue text, number, date, authors, readers, names and formula is not supported (yet....)
*/

      frm = document.forms[0] // current form
      fld = frm[fieldName]
      fldFound = false
      if (fld.type == undefined) // possibly radio or checkbox
      {
            if (fld[0].type == 'radio')
            {
                  fldFound = true
                  swE = returnSwitch(validationSwitches, 'E')
                  if (swE.split(' ')[0] == 'E')
                  {
                        checked = false
                        for (n=0; n<fld.length; n++)
                        {
                              checked = checked | fld[n].checked
                        }
                        if (checked == false)
                        {
                              msg = msg + 'No option selected at ' + fieldLable + '\n'
                              checkFocus(fld, true)
                        }
                  }
            } // radio
            
            if (fld[0].type == 'checkbox')
            {
                  fldFound = true
                  swE = returnSwitch(validationSwitches, 'E')
                  if (swE.split(' ')[0] == 'E')
                  {
                        nrChecked = 0
                        for (n=0; n<fld.length; n++)
                        {
                              if (fld[n].checked == true)
                              {
                                    nrChecked = nrChecked + 1
                              }
                        }
                        if (nrChecked == 0)
                        {
                              msg = msg + 'No option selected at ' + fieldLable + '\n'
                              checkFocus(fld, true)
                        }
                        swL = returnSwitch(validationSwitches, 'L')
                        if ((swL.split(' ')[0] == 'L') && (swL.split(' ').length>0))
                        {
                              if (swL.split(' ')[1] != '')
                              {
                                    if (parseInt(swL.split(' ')[1]) > nrChecked)
                                    {
                                          msg = msg + 'Select minimum ' + swL.split(' ')[1] + ' options for ' + fieldLable + '\n'
                                          checkFocus(fld, true)
                                    }
                              }
                        }
                        swU = returnSwitch(validationSwitches, 'U')
                        if ((swU.split(' ')[0] == 'U') && (swU.split(' ').length>0))
                        {
                              if (swU.split(' ')[1] != '')
                              {
                                    if (parseInt(swU.split(' ')[1]) < nrChecked)
                                    {
                                          msg = msg + 'Select maximum ' + swU.split(' ')[1] + ' options for ' + fieldLable + '\n'
                                          checkFocus(fld, true)
                                    }
                              }
                        }
                  }
            } // checkbox
            
      } // fieldtype == undefined
      else
      { // fieldtype != undefined
            if ((fld.type == 'text') || (fld.type == 'textarea') || (fld.type == 'password') || (fld.type == 'hidden'))
            {
                  fldFound = true
                  swE = returnSwitch(validationSwitches, 'E')
                  if (swE.split(' ')[0] == 'E')
                  {
                        if (fld.value == '')
                        {
                              msg = msg + fieldLable + ' has not been filled out yet\n'
                              checkFocus(fld, false)
                        }
                        else
                        {
                              // value was entered
                              swN = returnSwitch(validationSwitches, 'N')
                              if (swN.split(' ')[0] == 'N')
                              {
                                    checked = false
                                    sign = 0
                                    nrSep = 0
                                    numChars = '-1234567890' + decimalSeparator()
                                    // start looking for numeric errors
                                    for (n=0; n<fld.value.length; n++)
                                    {
                                          // check each position for non-numeric characters
                                          checked = checked | (numChars.indexOf(fld.value.charAt(n), sign) < 0)
                                          if (fld.value.charAt(n) == decimalSeparator())
                                          {
                                                nrSep ++ // count no. of decimal separators
                                          }
                                          sign = 1 // 1st char already verified; no longer accept '-'
                                    }
                                    if (nrSep > 1)
                                    {
                                          checked = true // multiple decimal separators = non-numeric error
                                    }
                                    if (checked == true)
                                    {
                                          msg = msg + fieldLable + ' contains non-numeric characters\n'
                                          checkFocus(fld, false)
                                    }
                                    else
                                    {
                                          swL = returnSwitch(validationSwitches, 'L')
                                          if ((swL.split(' ')[0] == 'L') && (swL.split(' ').length>0))
                                          {
                                                if (swL.split(' ')[1] != '')
                                                {
                                                      if (parseInt(swL.split(' ')[1]) > fld.value)
                                                      {
                                                            msg = msg + 'Minimum value for ' + fieldLable + ' is ' + swL.split(' ')[1] + '\n'
                                                            checkFocus(fld, false)
                                                      }
                                                }
                                          }
                                          swU = returnSwitch(validationSwitches, 'U')
                                          if ((swU.split(' ')[0] == 'U') && (swL.split(' ').length>0))
                                          {
                                                if (swU.split(' ')[1] != '')
                                                {
                                                      if (parseInt(swU.split(' ')[1]) < fld.value)
                                                      {
                                                            msg = msg + 'Maximum value for ' + fieldLable + ' is ' + swU.split(' ')[1] + '\n'
                                                            checkFocus(fld, false)
                                                      }
                                                }
                                          }
                                    } // checked == true
                              } // N
                              swD = returnSwitch(validationSwitches, 'D')
                              if (swD.split(' ')[0] == 'D')
                              {
                                    checked = false
                                    numChars = '1234567890' + dateSeparator()
                                    // start looking for numeric errors
                                    for (n=0; n<fld.value.length; n++)
                                    {
                                          // check each position for non-numeric characters
                                          checked = checked | (numChars.indexOf(fld.value.charAt(n)) < 0)
                                    }
                                    if (checked == true)
                                    {
                                          msg = msg + fieldLable + ' contains illegal characters. Please use ' + dateFormat() + '\n'
                                          checkFocus(fld, false)
                                    }
                                    else
                                    {
                                          sysAr = dateFormat().split(dateSeparator())
                                          fldAr = fld.value.split(dateSeparator())
                                          if (sysAr.length != fldAr.length)
                                          {
                                                msg = msg + 'illegal date format for ' + fieldLable + '. Please use ' + dateFormat() + '\n'
                                                checkFocus(fld, false)
                                          }
                                          else
                                          {
                                                // concatenate 1st char of sysAr (Y, M or D) to fldAr
                                                fldAr[0] = sysAr[0].charAt(0) + fldAr[0]
                                                fldAr[1] = sysAr[1].charAt(1) + fldAr[1]
                                                fldAr[2] = sysAr[2].charAt(2) + fldAr[2]
                                                // fldAr can now be sorted. compare function determines a descending order to deliver Y-M-D order
                                                fldAr = fldAr.sort(compare)
                                                // remove 1st character from the elements
                                                fldAr[0] = fldAr[0].substring(1, fldAr[0].length)
                                                fldAr[1] = fldAr[1].substring(1, fldAr[1].length)
                                                fldAr[2] = fldAr[2].substring(1, fldAr[2].length)
                                                // values can now be verified as a date
                                                dt = new Date(fldAr[0], (fldAr[1] - 1), fldAr[2])
                                                // compare newly generated date with the source elements
                                                dtY = dt.getYear()
                                                dtM = dt.getMonth() + 1 // 0 - 11
                                                dtD = dt.getDate()
                                                if (dtY<100) // 1900 - 1999 are returned in a 2 digit format
                                                {
                                                dtY = dtY + 1900
                                                }
                                                if ((dtY != fldAr[0]) || (dtM != fldAr[1]) || (dtD != fldAr[2]))
                                                {
                                                      msg = msg + 'invalid date for ' + fieldLable + '. Please use ' + dateFormat() + '\n'
                                                      checkFocus(fld, false)
                                                }
                                          } // sysAr.length
                                    } // checked == true
                              }
                        } // ''
                  } // E
            } // text....
            
            if (fld.type == 'select-one')
            {
                  fldFound = true
                  swE = returnSwitch(validationSwitches, 'E')
                  if (swE.split(' ')[0] == 'E')
                  {
                        if (fld.selectedIndex == -1)
                        {
                              msg = msg + 'No option selected at ' + fieldLable + '\n'
                              checkFocus(fld, false)
                        }
                        else
                        {
                              if (strTrim(fld.options[fld.selectedIndex].text) == '') // consider values containing only spaces as unselected
                              {
                                    msg = msg + 'No option selected at ' + fieldLable + '\n'
                                    checkFocus(fld, false)
                              }
                        }
                  }
            } // select-one
            
            if (fld.type == 'select-multiple')
            {
                  fldFound = true
                  swE = returnSwitch(validationSwitches, 'E')
                  if (swE.split(' ')[0] == 'E')
                  {
                        nrChecked = 0
                        for (n=0; n<fld.length; n++)
                        {
                              if (fld.options[n].selected == true)
                              {
                                    if (strTrim(fld.options[n].text) != '') // consider values containing only spaces as unselected
                                    {
                                          nrChecked = nrChecked + 1
                                    }
                              }
                        }
                        if (nrChecked == 0)
                        {
                              msg = msg + 'No option selected at ' + fieldLable + '\n'
                              checkFocus(fld, false)
                        }
                        swL = returnSwitch(validationSwitches, 'L')
                        if ((swL.split(' ')[0] == 'L') && (swL.split(' ').length>0))
                        {
                              if (swL.split(' ')[1] != '')
                              {
                                    if (parseInt(swL.split(' ')[1]) > nrChecked)
                                    {
                                          msg = msg + 'Select minimum ' + swL.split(' ')[1] + ' options for ' + fieldLable + '\n'
                                          checkFocus(fld, false)
                                    }
                              }
                        }
                        swU = returnSwitch(validationSwitches, 'U')
                        if ((swU.split(' ')[0] == 'U') && (swU.split(' ').length>0))
                        {
                              if (swU.split(' ')[1] != '')
                              {
                                    if (parseInt(swU.split(' ')[1]) < nrChecked)
                                    {
                                          msg = msg + 'Select maximum ' + swU.split(' ')[1] + ' options for ' + fieldLable + '\n'
                                          checkFocus(fld, false)
                                    }
                              }
                        }
                  } // E
            } // select-multiple
      } // fieldtype != undefined

      if (fldFound == false)
      {
            // field not found or type not recognised
            alert('Debug information:\nField \"' + fieldName + '\" not found, or\nunknown type: ' + fld.type)
      }
}


Fourth (last): you'll need to validate all required fields in a submit action:

msg = ''
fldFocus = ''
// single value fields
validate ('field1', 'your field number 1', 'E') // text
validate ('field2', 'your field number 2', 'E D') // date/time
validate ('field3', 'your field number 3', 'E N L5 U10') // number
validate ('field4', 'your field number 4', 'E') // dialog list
validate ('field6', 'your field number 6', 'E') // radio
validate ('field7', 'your field number 7', 'E') // listbox
validate ('field8', 'your field number 8', 'E') // combobox
validate ('field9', 'your field number 9', 'E') // textarea
if (msg != '')
{
      alert(msg)
}
else
{
      window.document.forms[0].submit()
}


The available switches and their interpretation may pend on the field that you use it on. The code holds documentation!
ote that after submit(), $$Return can be used again to determine what happens next.


Please let me know what you think of it....
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6652882
Intersting code, CRAK, but I've got my own form validation script, which is a lot shorter.
I just wrote a seperate function for different field types and then call these from my main validation function.
Anyway, in principle it's the same, so I'll leave the points for you.
0
 

Author Comment

by:hreinart
ID: 6654658
hi crack,

welcome back.
i'll need to reinstall this database to implement your suggestion.
where would i get the needed js-library?
would it it possible to send me a copy of your database (+ the lib?) to hr1@onlinehome.de

jerrith,
why don't you publish your version?
will it test all the needed fieldtypes?



thanks
hreinart
0
 
LVL 8

Expert Comment

by:Jean Marie Geeraerts
ID: 6655239
It's pretty customized, but I can probably generalize it for you. Remind me tomorrow so I don't forget.
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6656113
The js-library is the code under the 3rd step.
You could put in on a page, a form or in a document, as long as you don't have domino translate in to HTML again: it already is (well... kind of...).

Jerrith,
I could get it shorter too, but I don't want anyone figuring out how to validate a number or a date...
It's generic as you noticed.
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6783317
Still open today, if you need more help please add comments, since much time has passed so the Experts
can be advised of any progress you may have made here.

You have 18 open questions, all of which require your attention.  Please check the HELP DESK link on
the left for Member Agreement, Guidelines and the Question/Answer process.  If you need help to split
points, or other special handling of your questions or account, please post a zero point question in
Community Support with details.

Your attention to updating your open questions is not only needed, but appreciated.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6791280
hreinart---->  You've asked 46 questions here, only closed 34.  This is against our Guidelines.  Please see the links below if you have any questions in this regard, or comment here.    I think you'll agree that asking for help, getting feedback and not closing and awarding questions is not fair to those who help you.  

If you need help in splitting question points between experts, or otherwise in terms of special handling, just comment here, please, with details.  Or post a zero point question in Community Support with your request and the question link (QID).   If more is needed, please let the experts know.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please return and update/finalize all your open questions.  If not resolved in one week, we will need to take actions.  I will post this in all your open question, and also ask that you refer to this site's Guidelines and the Member Agreement you signed off on when you joined this site.  They are available here, as I said, here:

http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp
http://www.experts-exchange.com/jsp/infoMemberAgreement.jsp


Your responsiveness in finalizing them is not only needed, but appreciated.  They are:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=browsers&qid=20173133
http://www.experts-exchange.com/jsp/qShow.jsp?ta=win2k&qid=20181440
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20172093
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20171086
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20162886
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20162115
http://www.experts-exchange.com/jsp/qShow.jsp?ta=virus&qid=20260178
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20242901
http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20260175
http://www.experts-exchange.com/jsp/qShow.jsp?ta=win98&qid=20256256
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20262543
http://www.experts-exchange.com/jsp/qShow.jsp?ta=lotusnotes&qid=20260179


EXPERTS----> Please provide closing recommendations here, in the event this needs to be resolved by us and these questions are still open after 7 days.  You may want to check the link below, we added many new TOPIC AREAS yesterday:

http://www.experts-exchange.com/jsp/zonesAll.jsp

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 
LVL 13

Expert Comment

by:CRAK
ID: 6791484
Well, my code appears to work very well as a standard now for my (current and former) collegues....
I'd still like to hear from hreinhart though. It took me a while to find the time and write the code, and once I did hreinhart wrote that he couldn't get to it right away either.
I wouldn't mind waiting another while to get my comment evaluated properly!
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6791680
That is very generous of you CRAK, thank you for your dedication and hard work on this question.  I'm sure that hreinart appreciates that, and hope he/she returns soon to provide you some good news.

Thanks,

Moondancer
Community Support Moderator @ Experts Exchange
0
 

Author Comment

by:hreinart
ID: 6796152
would be nice to get the example sent in a database to:
hr1@onlinehome.de


thanks
hreinart
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now