-
A field.focus();
Hi,
I have an ASP page with around 55 input fields.
For most of them I do a quick validation (javascript) of value on submit event of the form.
If there is an error I do a " form.myfield.focus(); "
It correctly focuses the wanted field, BUT under the field I have an error message explaining what is wrong.
The problem is that if the submit event was triggered when the user was at the begginning of the form, the focus goes to the field which is of course lower, so the last viewable information on the browser will be my input field in error.
AND
Under the field is shown the error message and we can't see it.
-------
That only occurs when the submit event is launched when the user is at the begginning of the form, because if he is at the end, the focused field will show at the top of the browser and I will see the error message underneath.
-------
Is it possible when using " .focus(); " to have the focused field always displayed at the top of the browser ?
Hi hope it is clear enough.
Thanks.
-
Re: A field.focus();
There is a scrollTo method which takes an x and y coords, although I'm not sure how you determine the coords of the control to scroll to.
Alternatively 55 inputs on one page seems a lot, would it be possible to break it down to a three page process, fill in 20 then annother 20 and finally the last 15. having all the controls fitting on the page with out the user having to scroll.
-
Re: A field.focus();
I can't really break the form into multiple pages.
I have to reproduce a paper registration form and some of the last questions validate with what was entered in the first fields, It would be too complex to navigate between pages at that stage.
I will look at the ScrollTo stuff. Thanks.
-
Re: A field.focus();
In your javascript validation function, are you validating the lower input fields first, and the topmost ones last?
-
Re: A field.focus();
I found a way to work my problem.
At the very beginning of my validation function, I put the focus on the last input of my form. So I am sure that if there is an error, I will go up so I will see the error message underneath the field.
Surely not the best way, but if fits my needs.