Fastest finger first

P

Phil_Harvey

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.

Cheers
Phil.
 
E

Evertjan.

[Please give a relevant description to your Q]

Phil_Harvey wrote on 22 apr 2006 in comp.lang.javascript:
I need to know how I scroll to a particular element with javascript.

IE and possebly others have:

object.scrollIntoView( [bAlignToTop] )
<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.

Why not use:

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

script:

location.href='#here'
I have delbt with all the other stuff I want it to do, I just need to
know how to make it scroll.

A man of limited desires?
 
P

Phil_Harvey

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.
 
E

Evertjan.

Phil_Harvey wrote on 22 apr 2006 in comp.lang.javascript:
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?

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.
 
T

Touffy

Why not use:

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

script:

location.href='#here'

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.
 
E

Evertjan.

Touffy wrote on 22 apr 2006 in comp.lang.javascript:
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.

This script?:

location.href='#here'

I don't think so!

What srpt are you referring to?
 
P

pegasusflightresources

Phil_Harvey said:
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.

Cheers
Phil.

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.
 
P

pegasusflightresources

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
modification:
<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:
#scrolleditem
}
</script>
...

I remain your most humble and Ob't Sv't in our battle against the King.
 

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

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top