Scrolling to an internal Link

I

Iain Adams

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??
 
L

-Lost

Iain said:
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?
 
I

Iain Adams

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

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?
 
K

kaaposc

Iain said:
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).
 
S

scripts.contact

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()
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top