By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

Focus()

P: n/a
When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!
Sep 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Simon Wigzell <si**********@shaw.ca> wrote in message news:eACVe.478892$5V4.305000@pd7tw3no...
When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!

You could place one or more anchors at strategic points above the relevant fields:

<A name='fieldPoint'> </A>

then send the page there on error:

document.location='#fieldPoint';

--
S.C.

S.C.

Sep 13 '05 #2

P: n/a

"Stephen Chalmers" <ig******@lycos.co.uk> wrote in message
news:43**********@mk-nntp-2.news.uk.tiscali.com...
Simon Wigzell <si**********@shaw.ca> wrote in message
news:eACVe.478892$5V4.305000@pd7tw3no...
When I validate a form on submission I use the javascript focus function
to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of
the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get
the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location
of
the error field and then either add half a windows worth of pixels to it
if
it is at the top of the screen or subtract half a windows worth of pixels
to
it if it is at the bottom of the screen?

Thanks!

You could place one or more anchors at strategic points above the relevant
fields:

<A name='fieldPoint'> </A>

then send the page there on error:

document.location='#fieldPoint';

--
S.C.

S.C.

Thanks, that syntax is new to me, that will do it.
Sep 14 '05 #3

P: n/a
Stephen Chalmers wrote:
Simon Wigzell <si**********@shaw.ca> wrote in message news:eACVe.478892$5V4.305000@pd7tw3no...
When I validate a form on submission I use the javascript focus function to
scroll the page to the location of the form error e.g.

document.[Form Name].[Field Name].focus();

If you happened to have the page scrolled above where the error field is
then the page will scroll so that the error field is at the very top of the
window. If you happened to have the page scrolled below where the error
field is then the page will scroll so that the error field is at the very
bottom of the window. Neither of these is very desirable. Any way to get the
error field to the middle of the window?

e.g. in javascript after the focus statement, can one test the location of
the error field and then either add half a windows worth of pixels to it if
it is at the top of the screen or subtract half a windows worth of pixels to
it if it is at the bottom of the screen?

Thanks!


You could place one or more anchors at strategic points above the relevant fields:

<A name='fieldPoint'> </A>

then send the page there on error:

document.location='#fieldPoint';


Anchors can be created using element ids, A elements aren't required.

It may be useful to use the id of the form as an anchor or the id of
some fieldset inside the form.

<form id="formA" ...>
<!-- controls for for formA -->
</form>

<a href="#formA">Scroll to formA</a>


[...]

--
Rob
Sep 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.