• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Best way to validate text field using javascript based on cursor

 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have 5 text fields and I want to validate each text field before the cursor goes to the next text-field. Instead of mouse events or key events  is there any effective methods that I should use ?

--Thanks
--Rajeev
 
Maneesh Godbole
Bartender
Posts: 11445
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajeev Srikhar wrote: Instead of mouse events or key events


Why can't you use mouse/key events?

You can consider using onBlur()
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Javascript you can use onchange attribute of a textbox which will call a function when the text box looses focus.
If you are using JQuery (JQuery has lot of advantages over plain Javascript) you can make use of the "blur" function, which is called when textbox looses focus.
You can go through this
 
Rajeev Srikhar
Ranch Hand
Posts: 75
Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I made the the above changes like you both suggested.
But when I place the cursor in the second text-box without entering details in first text-box I get a alert box, after pressing the 'ok' button the cursor is still in second text-box but I want to make the cursor to come the first text-box because first text-box is not valid.

So, which way is better

1. Simply showing alert box on typing invalid input in each text-box and doing validation check once again for all text-boxes before submitting the form.
2. Making sure that user enter correct input in a text-box before he enters the second text-box.

--Thanks in advance
--Rajeev
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on your client's requirement.
In the past we have implemented both the scenarios mentioned by you for different clients.
But most of them went for the 1st approach.
Fewer clients went for the 2nd approach as user can become frustrated if not allowed to go anywhere on browser without valid input.
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing...in Javascript, comments are just like Java.
// for single line comment
/**/ for multiline comment.
<!-- --> this type of comment applies to HTML and XML.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic