Focus() and browser positioning

D

donpro

Hi,

I have several forms that are presented with the field description on
top of either the Text Input or Text Area. I have programmed it so
that when the user clicks "SUBMIT", it verifies that necessary fields
have been populated. If not, it alerts the user and sets focus to the
empty field.

If the form is longer than the screen window (vertical scroll bar), I
have found that the browser will position the screen so the the
missing field with focus is presented at the top of the screen. The
side effect is that the field description, which resides above it, is
not seen.

Is there a trick that will return focus to the empty field and also
adjust the browser view to show the field description above it?

Thanks,
Don
 
M

Martin Honnen

donpro said:
Is there a trick that will return focus to the empty field and also
adjust the browser view to show the field description above it?

You might want to try to call
formControl.focus();
fieldYouWantToShow.scrollIntoView(true);
 
D

donpro

You might want to try to call
   formControl.focus();
   fieldYouWantToShow.scrollIntoView(true);

Thanks. Sounds promising but what if the field I want to show is not a
field but just text enclosed in a <DIV> with an ID tag? Or...., is
this considered a field when I use DOM?
 
T

Thomas 'PointedEars' Lahn

donpro said:
Martin said:
donpro said:
Is there a trick that will return focus to the empty field and also
adjust the browser view to show the field description above it?
You might want to try to call
formControl.focus();
fieldYouWantToShow.scrollIntoView(true);
[...]

Thanks. Sounds promising but what if the field I want to show is not a
field but just text enclosed in a <DIV> with an ID tag?

scrollIntoView(), where it works, should work with any visible element,
including `div' elements. You should employ feature testing before you
call it, of course.

Or...., is this considered a field when I use DOM?

No.

Please trim your quotes. <http://jibbering.com/faq/#posting>


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top