Field Validation Tips 
Author Message
 Field Validation Tips

I would like to know the best way to validate a field.  When I use onblur,
the event fires when I minimize the screen which can be a hassle to the
end-user.  When I use onchange, it really doesn't force the correction of
errors since the user can make an error, the program puts him back on the
field, and then tabbing down gets him off the field with bad data on the
field.  Sure I could blank out the field but he can tab down with a blank in
that field.

What am I missing?

TIA,
Brian Sabolik



Tue, 17 Dec 2002 03:00:00 GMT  
 Field Validation Tips
Hi Brian

May be this is not the best suggestion, but I never do on-editing validations
due to the problems you pointed out. I usually set up a validation function for
the whole form and call it from the form's onsubmit event. I think it's much
easier because this approach avoid those errors and you centralize the whole
code in one function.

Klaus

Quote:

> I would like to know the best way to validate a field.  When I use onblur, the
> event fires when I minimize the screen which can be a hassle to the end-user.
> When I use onchange, it really doesn't force the correction of errors since
> the user can make an error, the program puts him back on the field, and then
> tabbing down gets him off the field with bad data on the field.  Sure I could
> blank out the field but he can tab down with a blank in that field.

> What am I missing?

> TIA,
> Brian Sabolik



Wed, 18 Dec 2002 03:00:00 GMT  
 Field Validation Tips
Brian
I personally use onchange events for each field. However, as you stated
a user can ignore your warning and proceed, leaving bad data in the
field. To catch the bad data and also check for required fields, I use
an onsubmit event function to go through the form elements and validate
each text form element with a defined onchange/onblur event function. Be
certain your onchange functions return true/false.

Arn

The following is an excerpt(read Untested and very much reduced) from
some code I developed and use at a client site. It assumes one form per
document but is easily changed for multiple forms.

function FormVerify() {
// Loop through the elements of the form,
// executing any onchange or onblur functions for text fields
var f=document.forms(0)                 //set some shorthand for form    
var x
var e
for(var i = 0; i < f.length; i++) {
    e = f.elements[i];                 //shorthand for element
    if (e.disabled==false) {           // process only enabled fields
    switch (e.type) {                  // process the various form
elements by type
        case "text":
        // Check for an onchange or onblur handler and execute the code
          if (e.onchange != null)
                {
                x=e.onchange()         //execute function and get
true/false in x                     if (x == false)      
                        return false
                }
          else
          if (e.onblur != null)
                {
                x=e.onblur()
                if (x == false)
                        return false
                }

          break;

       case "radio":
         //YOUR CODE HERE                                    
         break;

       case "select-one":                            
         //YOUR CODE HERE
       break;

       // YOUR CODE HERE for other form element types

Quote:
}}}

// since this point was reached all data is good
return true;

Quote:
}

--
Arn
http://www.injersey.infi.net/~arneb/
Quote:

> I would like to know the best way to validate a field.  When I use onblur,
> the event fires when I minimize the screen which can be a hassle to the
> end-user.  When I use onchange, it really doesn't force the correction of
> errors since the user can make an error, the program puts him back on the
> field, and then tabbing down gets him off the field with bad data on the
> field.  Sure I could blank out the field but he can tab down with a blank in
> that field.

> What am I missing?

> TIA,
> Brian Sabolik



Wed, 18 Dec 2002 03:00:00 GMT  
 Field Validation Tips


Fri, 19 Jun 1992 00:00:00 GMT  
 Field Validation Tips
Oh by the way,  I should have stated that I am not using forms.  This is an
order entry application written in DHTML running only on IE5 +.   It should
act pretty much like a VB application.  The user may stay on this one window
for a whole day entering orders!  So far, the only thing I've heard is that
I can warn the user but would have to do a final catch-all check before
updating the mainframe.

TIA,
Brian Sabolik


Quote:
> I would like to know the best way to validate a field.  When I use onblur,
> the event fires when I minimize the screen which can be a hassle to the
> end-user.  When I use onchange, it really doesn't force the correction of
> errors since the user can make an error, the program puts him back on the
> field, and then tabbing down gets him off the field with bad data on the
> field.  Sure I could blank out the field but he can tab down with a blank
in
> that field.

> What am I missing?

> TIA,
> Brian Sabolik



Wed, 18 Dec 2002 03:00:00 GMT  
 Field Validation Tips
Hi Brian

How are you updating the mainframe? With Remote Scripting? Anyway explain how
are you performing this update. Maybe then we can tell you where to put the
validation function or whatever.

Klaus

Quote:

> Oh by the way,  I should have stated that I am not using forms.  This is an
> order entry application written in DHTML running only on IE5 +.   It should
> act pretty much like a VB application.  The user may stay on this one window
> for a whole day entering orders!  So far, the only thing I've heard is that I
> can warn the user but would have to do a final catch-all check before updating
> the mainframe.

> TIA,
> Brian Sabolik



> > I would like to know the best way to validate a field.  When I use onblur,
> > the event fires when I minimize the screen which can be a hassle to the
> > end-user.  When I use onchange, it really doesn't force the correction of
> > errors since the user can make an error, the program puts him back on the
> > field, and then tabbing down gets him off the field with bad data on the
> > field.  Sure I could blank out the field but he can tab down with a blank in

> > that field.

> > What am I missing?

> > TIA,
> > Brian Sabolik



Thu, 19 Dec 2002 03:00:00 GMT  
 Field Validation Tips
Yes, I am updating/validating with remote scripting.  Since an order could
have up to 999 line items I may try to do something like have some temp
storage on the client in case of a power failure or loss of an internet
line....  Maybe I might use an XML format or an EDI ANSI X12 format.  I
might invoke a ftp session to transfer to the mainframe at "submit" time...
I'm not sure yet.  As far as field validation goes.... I've pretty much
decided that I will use the on-change event and make sure that all non-blank
fields are validated and then have the final "submit" check required fields
against a blank.  In that way I don't have to re-validate existing data
since that would require a round trip to the server with remote scripting..

Regards,
Brian



Quote:
> Hi Brian

> How are you updating the mainframe? With Remote Scripting? Anyway explain
how
> are you performing this update. Maybe then we can tell you where to put
the
> validation function or whatever.

> Klaus


> > Oh by the way,  I should have stated that I am not using forms.  This is
an
> > order entry application written in DHTML running only on IE5 +.   It
should
> > act pretty much like a VB application.  The user may stay on this one
window
> > for a whole day entering orders!  So far, the only thing I've heard is
that I
> > can warn the user but would have to do a final catch-all check before
updating
> > the mainframe.

> > TIA,
> > Brian Sabolik



> > > I would like to know the best way to validate a field.  When I use
onblur,
> > > the event fires when I minimize the screen which can be a hassle to
the
> > > end-user.  When I use onchange, it really doesn't force the correction
of
> > > errors since the user can make an error, the program puts him back on
the
> > > field, and then tabbing down gets him off the field with bad data on
the
> > > field.  Sure I could blank out the field but he can tab down with a
blank in

> > > that field.

> > > What am I missing?

> > > TIA,
> > > Brian Sabolik



Sun, 22 Dec 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Basic Form Field Validation

2. !!!!-=-=field validation-=-=-!!!!!!!!!!!!

3. Select Field Validation

4. Field Validation

5. DHTML Field Validation

6. Validation of field : onsubmit, onblur.

7. Form Field Validation

8. Field validation sample code

9. Client side form field validation

10. Client side VBS form field validation

11. Field Validation

12. Client side field validation

 

 
Powered by phpBB® Forum Software