Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

General question on validating textbox entries using the .blur event

 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Melinda Savoy
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I'll start down this path.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic