Scrolling to an internal Link

Discussion in 'Javascript' started by Iain Adams, Jun 18, 2007.

  1. Iain Adams

    Iain Adams Guest

    Hello,

    I have a page with a text field. When something is typed into the text
    field and a button is clicked I want the page to scroll to the
    relevant place on the page that has the value of the text field as its
    name.

    i.e

    A piece of information

    <span name="gohere">
    hello world
    </span>

    I then have an input field and a button. If "gohere" is entered and
    the button clicked I want the page to scroll to the span above (like
    an internal link) Is this possible??
     
    Iain Adams, Jun 18, 2007
    #1
    1. Advertising

  2. Iain Adams

    -Lost Guest

    Iain Adams wrote:
    > Hello,
    >
    > I have a page with a text field. When something is typed into the text
    > field and a button is clicked I want the page to scroll to the
    > relevant place on the page that has the value of the text field as its
    > name.
    >
    > i.e
    >
    > A piece of information
    >
    > <span name="gohere">
    > hello world
    > </span>
    >
    > I then have an input field and a button. If "gohere" is entered and
    > the button clicked I want the page to scroll to the span above (like
    > an internal link) Is this possible??


    Hrmm... probably yes. However, wouldn't using named anchors be much
    more suitable?

    --
    -Lost
    Remove the extra words to reply by e-mail. Don't e-mail me. I am
    kidding. No I am not.
     
    -Lost, Jun 18, 2007
    #2
    1. Advertising

  3. Iain Adams

    Iain Adams Guest

    On 18 Jun, 14:26, -Lost <> wrote:
    > Iain Adams wrote:
    > > Hello,

    >
    > > I have a page with a text field. When something is typed into the text
    > > field and a button is clicked I want the page to scroll to the
    > > relevant place on the page that has the value of the text field as its
    > > name.

    >
    > > i.e

    >
    > > A piece of information

    >
    > > <span name="gohere">
    > > hello world
    > > </span>

    >
    > > I then have an input field and a button. If "gohere" is entered and
    > > the button clicked I want the page to scroll to the span above (like
    > > an internal link) Is this possible??

    >
    > Hrmm... probably yes. However, wouldn't using named anchors be much
    > more suitable?
    >
    > --
    > -Lost
    > Remove the extra words to reply by e-mail. Don't e-mail me. I am
    > kidding. No I am not.


    Well yeah named anchors would be good. But Say I have thousands of
    places I want to jump to. Then I wud have to have thousands of links.
    <a href="#gohere">. This probaly wouldnt be much good. What i want is
    a named anchor but without the actual anchor. haha. Basically i want
    to replicate what the named anchor does but when a button is clicked
    and using the name given in a text field. Do you know how to do this?
     
    Iain Adams, Jun 18, 2007
    #3
  4. Iain Adams

    kaaposc Guest

    Iain Adams wrote:
    > On 18 Jun, 14:26, -Lost <> wrote:
    >> Iain Adams wrote:
    >>> Hello,
    >>> I have a page with a text field. When something is typed into the text
    >>> field and a button is clicked I want the page to scroll to the
    >>> relevant place on the page that has the value of the text field as its
    >>> name.
    >>> i.e
    >>> A piece of information
    >>> <span name="gohere">
    >>> hello world
    >>> </span>
    >>> I then have an input field and a button. If "gohere" is entered and
    >>> the button clicked I want the page to scroll to the span above (like
    >>> an internal link) Is this possible??

    >> Hrmm... probably yes. However, wouldn't using named anchors be much
    >> more suitable?
    >>
    >> --
    >> -Lost
    >> Remove the extra words to reply by e-mail. Don't e-mail me. I am
    >> kidding. No I am not.

    >
    > Well yeah named anchors would be good. But Say I have thousands of
    > places I want to jump to. Then I wud have to have thousands of links.
    > <a href="#gohere">. This probaly wouldnt be much good. What i want is
    > a named anchor but without the actual anchor. haha. Basically i want
    > to replicate what the named anchor does but when a button is clicked
    > and using the name given in a text field. Do you know how to do this?
    >


    what about the same old named anchors and button with
    onclick="location.href='#'+document.getElementById('text_field').value" ?

    see, if you want to scroll page to some span you first need to find that
    span according to what user typed in text field, then you need to
    calculate offset of that span and then scroll there (something like
    "document.scrollTop=there", not sure if correct syntax, check it out).
     
    kaaposc, Jun 18, 2007
    #4
  5. On Jun 18, 5:19 am, Iain Adams <> wrote:
    > Hello,
    >
    > I have a page with a text field. When something is typed into the text
    > field and a button is clicked I want the page to scroll to the
    > relevant place on the page that has the value of the text field as its
    > name.



    var elem=document.getElementsByName(textFieldValue)
    if(elem)elem.scrollIntoView()
     
    scripts.contact, Jun 18, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kevin Spencer

    Re: Link Link Link DANGER WILL ROBINSON!!!

    Kevin Spencer, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    882
    Kevin Spencer
    May 17, 2005
  2. Graham Thomson
    Replies:
    3
    Views:
    479
    Eki Y. Baskoro
    Dec 18, 2003
  3. Andrew S.

    Internal link help

    Andrew S., Jan 5, 2004, in forum: HTML
    Replies:
    7
    Views:
    398
    Andrew S.
    Jan 5, 2004
  4. Grant Robertson
    Replies:
    10
    Views:
    569
    Grant Robertson
    Apr 11, 2007
  5. Replies:
    0
    Views:
    125
Loading...

Share This Page