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

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.
Who is Participating?
Dobromir YordanovConnect With a Mentor Commented:
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
 //assuming valid is a boolean which is true if the data was valid

Open in new window

Let me know if you need help implementing this.
BhanuSVSAuthor Commented:
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.
BhanuSVSAuthor Commented:
Dear CrackPack,

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

Please do needful.
BhanuSVSAuthor Commented:
Please try to respond for the second time.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.