Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with my javascript!!!

    Ok,here it is:
    We got the gallery made using a table, say, 2 by 3, with a thumb in each cell (they all got the corresponding id's: g0,g1,g2,...). Under the table there are digits for gallery page navigation (1,2,..), clicking on which we going to the desired gallery thumb set (in code it looks like simply reassigning .src property of each thumb in the table to new image source).
    The problem is that after switching to another set it looks like my whole page is being reloaded, that is, if our gallery table is located somewhere deep down the page, after swapping sets we are being thrown back up to the top of the page.
    What should be done to keep having the table in the focus ???!!!

    Here is the part of the script:

    function changePage(){
    var srcEl=event.srcElement;
    var pgNum=srcEl.id.substr(1);
    var nextBlckSt=imgPerPage*(pgNum-1)+1;
    if(nextBlckSt+imgPerPage>imgCount){
    var trNum=(nextBlckSt+imgPerPage)-imgCount+1;
    for(i=0;i<imgPerPage-trNum;i++){
    var g=trNum+i;
    document.all['g'+g].src='images/misc/null.gif';
    }
    }
    else{
    var trNum=imgPerPage;
    }
    for(i=0;i<trNum;i++){
    document.all['g'+i].src=imgArray[nextBlckSt-1+i].src;
    }
    }

    thanx in advance for any help and suggestions!

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,946
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Without seeing how you call the function, I'd guess that the links look like this.

    <a href="#" onclick="changePage()">1</a>

    You'd need to return false to the onclick handler to cancel the link action.

    <a href="#" onclick="changePage();return false;">1</a>

    or better, put the return false at the end of changePage() function and call it like this:

    <a href="#" onclick="return changePage()">1</a>

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    WOW!!!
    YOU ARE THE MAN!!!

    thanx, it works like a dream!!!
    thanx a lot once again!!!


  •  

    Posting Permissions

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