Results 1 to 5 of 5

Thread: A field.focus();

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    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.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    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.

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: A field.focus();

    In your javascript validation function, are you validating the lower input fields first, and the topmost ones last?

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width