File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes validating mulitple fields with the blur event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "validating mulitple fields with the blur event" Watch "validating mulitple fields with the blur event" New topic

validating mulitple fields with the blur event

J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632

I have a form with 13 text input boxes. I'm trying to validate each one as the user tabs out of the field like so:

My problem is that the cursor has moved to the next field by the time this runs, so when the line "$('#conversionData').focus().select();" runs to move the cursor back to the field with the error, it triggers the blur event on the following field resulting in an error message for a field that, as far as the user is concerned, they haven't even tried to enter data yet.

The only solution I can think of is to wait and do all validation after the submit button is clicked, resulting in possibly multiple error messages at once. I know that most websites validate after you click the submit button so maybe that's what users expect and I shouldn't break that paradigm?

Am I missing another technique for validating each field one at a time? Waiting for the button to be clicked seems like late in the process for validation, but that's just my personal opinion.

"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60046

As you are a already using jQuery I see no reason that you shouldn't be using the validation plugin.

It waits until the form is submitted to validate, but once that happens, each field is validated individually. It will even remove error messages as the input of the individual fields satisfy the validation rules.

I think that'd be a much better approach than trying to roll your own.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632

Thanks for the tip, Bear. I'll go download that plugin now and take a look at it. I saw it mentioned in several of my searches but I haven't tried it yet.
subject: validating mulitple fields with the blur event
Similar Threads
Check which button was clicked Form Plugin
General question on validating textbox entries using the .blur event
Is there something better then event.pageX/Y?
Prevent the page refreshing