Solved

How to hold cursor position in the same field if it is having validation errors?

Posted on 2012-03-12
4
419 Views
Last Modified: 2012-04-14
Dear Experts,

I have a requirement, if the first field having validation error, then the system should not allow us to go to next field in the screen. the cursor position should be hold in the same field.

Please provide me the solution to achieve this, with Java Script/Ajax/JSF.

In my last query, experts are advised me to use PhaseListener, but it showing validation errors, but it is not restricting, it is allowing to go to next field.

kindly help me.
0
Comment
Question by:BhanuSVS
  • 3
4 Comments
 
LVL 5

Accepted Solution

by:
Dobromir Yordanov earned 500 total points
ID: 37712890
You only need javascript to do what you have requested. I'm not sure how exactly it would integrate into your code as I haven't seen it but generally you can check if the field has valid information in it after it loses focus which can easily be done in javascript and jquery and then if validation fails, force focus back to that field againg with javascript or jquery. I have a mini code snippet to show you how to do that in jquery

$("#yourField").focusout(function() {
//some validation code
if(!valid)
{
 //assuming valid is a boolean which is true if the data was valid
 $("#yourField").focus();
}
});

Open in new window


Let me know if you need help implementing this.
0
 

Author Comment

by:BhanuSVS
ID: 37723119
Dear CrackPack,

Thanks a lot for your suggestion.

I am new to JavaScript, please give me complete code , i.e all functions code, so i can understand and apply to my JSF application.
0
 

Author Comment

by:BhanuSVS
ID: 37727483
Dear CrackPack,

Complete code in the sense, i am expecting a simple example, with code.

Please do needful.
0
 

Author Closing Comment

by:BhanuSVS
ID: 37846302
Please try to respond for the second time.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now