Focus()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Wigzell

    Focus()

    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!


  • Stephen Chalmers

    #2
    Re: Focus()

    Simon Wigzell <simonwigzell@s haw.ca> wrote in message news:eACVe.4788 92$5V4.305000@p d7tw3no...[color=blue]
    > 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!
    >
    >[/color]
    You could place one or more anchors at strategic points above the relevant fields:

    <A name='fieldPoin t'> </A>

    then send the page there on error:

    document.locati on='#fieldPoint ';

    --
    S.C.

    S.C.



    Comment

    • Simon Wigzell

      #3
      Re: Focus()


      "Stephen Chalmers" <ignoring@lycos .co.uk> wrote in message
      news:432761b6$1 _1@mk-nntp-2.news.uk.tisca li.com...[color=blue]
      > Simon Wigzell <simonwigzell@s haw.ca> wrote in message
      > news:eACVe.4788 92$5V4.305000@p d7tw3no...[color=green]
      >> 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!
      >>
      >>[/color]
      > You could place one or more anchors at strategic points above the relevant
      > fields:
      >
      > <A name='fieldPoin t'> </A>
      >
      > then send the page there on error:
      >
      > document.locati on='#fieldPoint ';
      >
      > --
      > S.C.
      >
      > S.C.
      >
      >
      >[/color]
      Thanks, that syntax is new to me, that will do it.


      Comment

      • RobG

        #4
        Re: Focus()

        Stephen Chalmers wrote:[color=blue]
        > Simon Wigzell <simonwigzell@s haw.ca> wrote in message news:eACVe.4788 92$5V4.305000@p d7tw3no...
        >[color=green]
        >>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!
        >>
        >>[/color]
        >
        > You could place one or more anchors at strategic points above the relevant fields:
        >
        > <A name='fieldPoin t'> </A>
        >
        > then send the page there on error:
        >
        > document.locati on='#fieldPoint ';[/color]

        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">S croll to formA</a>








        [...]

        --
        Rob

        Comment

        Working...