my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes General question on validating textbox entries using the .blur event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "General question on validating textbox entries using the .blur event" Watch "General question on validating textbox entries using the .blur event" New topic
Author

General question on validating textbox entries using the .blur event

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

I am sure that this is a BASIC question for javascript gurus but I'm struggling to resolve.

The form starts with the cursor focus in the FROM ACCT NUMBER FIELD. When I tab to the next field without entering any value in this text field I want to send an alert to the user that the field is required and put the cursor back on that field. I attempted to do that using:



I do get the ALERT however when I click on the OK button on my alert dialog box the alert for the next field call TO ACCT NUMBER FIELD then gets executed because I tabbed to that field and then I get stuck in a loop literally where when I click on the second dialog box it goes back to the first dialog box for the first field.

My question is HOW can I force the cursor back to the FROM ACCT NUMBER FIELD and not execute the alert for the field that I tried to tab to. Is there a better event to use than the .blur event?

I hope this makes sense. Any help/direction would be greatly appreciated.

Thank you.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

As you are already using jQuery, I highly recommend the jQuery Validation Plugin which has already solved all the knotty problems. Why re-invent the wheel?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Thanks for the reply. I'll start down this path.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

The plugin has lots of nice things about it that would be really hard to do on our own.

For example, once validation messages are displayed, they are individually removed as the user fixes each field that is in error. That's a really nice feature that users really seem to appreciate.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Just to let you know, you are following some bad practices in that code block you posted.




You can do something like this:



Cleaner and easier to understand.

Eric
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 387

Eric - thanks for the js lesson. It's appreciated. However, does this new code prevent the issue of the loop that I spoke of earlier?

Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: General question on validating textbox entries using the .blur event