• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

General question on validating textbox entries using the .blur event

 
Ranch Hand
Posts: 387
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. I'll start down this path.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic