Fastest finger first

Discussion in 'Javascript' started by Phil_Harvey, Apr 22, 2006.

  1. Phil_Harvey

    Phil_Harvey Guest

    I need to know how I scroll to a particular element with javascript.

    <label>&gt; <input name="tf_command" size="50" type="text"></label>

    for example I want the screen to scroll to this input box whenever
    something is entered.
    I have delbt with all the other stuff I want it to do, I just need to
    know how to make it scroll.

    Phil_Harvey, Apr 22, 2006
    1. Advertisements

  2. Phil_Harvey

    Evertjan. Guest

    [Please give a relevant description to your Q]

    Phil_Harvey wrote on 22 apr 2006 in comp.lang.javascript:
    IE and possebly others have:

    object.scrollIntoView( [bAlignToTop] )
    Why not use:

    <a name='here'></a>
    &gt; <input name="tf_command" size="50" type="text">


    A man of limited desires?
    Evertjan., Apr 22, 2006
    1. Advertisements

  3. Phil_Harvey

    Phil_Harvey Guest

    The older I get, the more that I code, the more I realise that things
    should be small and simple. Desires, wishes, methods, questions,
    answers. Ask small and ask many.

    I think the location.href is a good option. I do have to make sue it
    fits with the other bits and squiggles in my code.

    Is window.scrollto supported in all browsers?

    Thank you very much.
    Phil_Harvey, Apr 22, 2006
  4. Phil_Harvey

    Evertjan. Guest

    Phil_Harvey wrote on 22 apr 2006 in comp.lang.javascript:
    I only test IE & FF, and would like to test Safari.

    scrollto() I never tested yet.

    Strange, btw, scrollTo and scrollBy
    are only defined for the window object,
    should also be nice for scrollable divs.
    Evertjan., Apr 22, 2006
  5. Phil_Harvey

    Touffy Guest

    a similar but slightly shorter (and simpler) way to define fragment
    identifiers is to use the id attribute of any element (should work with
    all browsers that support HTML 4).

    so, no <a>, just change the <input> to this :

    <input id="here" name="tf_command" size="50" type="text">

    and use the same script to scroll.
    Touffy, Apr 22, 2006
  6. Phil_Harvey

    Evertjan. Guest

    Touffy wrote on 22 apr 2006 in comp.lang.javascript:
    This script?:


    I don't think so!

    What srpt are you referring to?
    Evertjan., Apr 22, 2006
  7. Just a quick thought, you could use internal links in order to scroll
    to the anchor. Although this wouldn't exactly "scroll", it would bring
    you there. If you have any information that needs to stay in place in
    a dynamic form element, please disregard this comment, as internal
    links reload the page into a certain configuration, removing all
    dynamic form info.
    pegasusflightresources, Apr 23, 2006
  8. With this internal linking structure, you could just use the onChange
    event in order to have the site execute a script every time the client
    changes the input box. Using that, you could add a simple
    <input type=text name="..." onChange()="internal_link_scroll();">
    <script type="text/javascript">
    function internal_link_scroll
    location.href = "whatever your internal link's name is, preceded by
    a pound sign (#)"; //Your internal link might be something like:

    I remain your most humble and Ob't Sv't in our battle against the King.
    pegasusflightresources, Apr 23, 2006
  9. Phil_Harvey

    Touffy Guest

    yes, this very script. The id attribute in any displayed element is
    treated just like the name attribute in <a> tags, as far as fragment
    identifiers are connerned, including the way you refer to them in a URL.
    Touffy, Apr 26, 2006
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.