Connecting Tech Pros Worldwide Forums | Help | Site Map

Window scrolling (clarification)

Ethan
Guest
 
Posts: n/a
#1: Jul 20 '05
This is a clarification of a previous message, which was not expressed
very well. I have a set of checkboxes near the bottom of the page and
a function that checks or unchecks all of them. But when the function
runs, the window scrolls to the top of the page.

How can I set my checkboxes but leave the window's scroll position
exactly where it is? Or at least have it scroll to the bottom (where
the checkboxes are).

I've tried using window.scrollTo(), but the window always scrolls to
the top no matter what. It's the same in Navigator and IE.

Here's my code:

function checkAll(whichForm, startIndex, endIndex)
{
for (var j = startIndex; j <= endIndex; j++)
{
document.forms[whichForm].elements[j].checked = true;
}
window.scrollTo(0, 1000);
}

Thanks,

Ethan

Fred Serry
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Window scrolling (clarification)



"Ethan" <elektrophyte@yahoo.com> schreef in bericht
news:55447041.0307021144.4796d248@posting.google.c om...[color=blue]
> This is a clarification of a previous message, which was not expressed
> very well. I have a set of checkboxes near the bottom of the page and
> a function that checks or unchecks all of them. But when the function
> runs, the window scrolls to the top of the page.
>
> How can I set my checkboxes but leave the window's scroll position
> exactly where it is? Or at least have it scroll to the bottom (where
> the checkboxes are).
>
> I've tried using window.scrollTo(), but the window always scrolls to
> the top no matter what. It's the same in Navigator and IE.
>
> Here's my code:
>
> function checkAll(whichForm, startIndex, endIndex)
> {
> for (var j = startIndex; j <= endIndex; j++)
> {
> document.forms[whichForm].elements[j].checked = true;
> }
> window.scrollTo(0, 1000);
> }
>
> Thanks,
>
> Ethan[/color]

Hi,

Can you show how this function is called? I suspect you are using something
like:

<a href="#" onclick="checkAll(blabla)">

If so, add a "return false" to prevent the link to do its actual work

<a href="#" onclick="checkAll(blabla);return false">

Fred


Ethan
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Window scrolling (clarification)


"Fred Serry" <fred.NOSPAM.serry@planet.nl> wrote in message news:<bdvdne$11u2ds$1@ID-108377.news.dfncis.de>...[color=blue]
> "Ethan" <elektrophyte@yahoo.com> schreef in bericht[/color]
....[color=blue][color=green]
> > How can I set my checkboxes but leave the window's scroll position
> > exactly where it is? Or at least have it scroll to the bottom (where
> > the checkboxes are).
> >
> > I've tried using window.scrollTo(), but the window always scrolls to
> > the top no matter what.[/color][/color]
....[color=blue]
> Hi,
>
> Can you show how this function is called? I suspect you are using something
> like:
>
> <a href="#" onclick="checkAll(blabla)">
>
> If so, add a "return false" to prevent the link to do its actual work
>
> <a href="#" onclick="checkAll(blabla);return false">
>
> Fred[/color]

That's the answer. Thank you very much.

Ethan
Closed Thread