www.webdeveloper.com
Results 1 to 2 of 2

Thread: Newbie question. Set browser to the top after javascript next page command

  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Newbie question. Set browser to the top after javascript next page command

    Hello,

    I am sorry if this has been answered before but I didn't find it. I am new to Javascript and have inherited a site to look after.

    On the site I have a table with information and at the bottom a next page link which takes you to page 2 using javascript (so no postback). The code works but when you go to the next page the browser is stays at the bottom of the page (because it is not reloading). I like it that there is no postback but I would like the cursor to be at the top. My Code is:

    <script language="javascript">
    <!--
    function __onPrevPage ()
    {
    for (var i=2; i<6; i++) {
    if (document.getElementById ("Page" +i).
    style.display == "block") {
    document.getElementById ("Page" + i).
    style.display = "none";
    document.getElementById ("Page" + (i - 1)).
    style.display = "block";
    break;
    }
    }
    }

    function __onNextPage ()
    {
    for (var i=1; i<5; i++) {
    if (document.getElementById ("Page" + i).
    style.display == "block") {
    document.getElementById ("Page" + i).
    style.display = "none";
    document.getElementById ("Page" + (i + 1)).
    style.display = "block";
    break;
    }
    }
    }
    -->
    </script>

    and in the body we have:

    <div id="Page1" style="display: block"> then the table stuff etc...

    <div id="Page2" style="display: none">

    Any ideas will be truely appreciated.

    Thanking you in advance

    Sonia

  2. #2
    Join Date
    Aug 2010
    Posts
    2
    Hello Everybody

    I realised I missed out the last piece of the Javascript,

    <a href="javascript:__onPrevPage ();">Prev</a> &nbsp; <a href="javascript:__onNextPage ();">Next</a>
    <p>&nbsp;</p>

    Anybody have any ideas?

    Thanks Sonia

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles