...

View Full Version : Need help with my javascript!!!



hypeartist
06-15-2004, 11:48 AM
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!

glenngv
06-15-2004, 12:01 PM
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>

hypeartist
06-15-2004, 12:23 PM
WOW!!! :thumbsup: :thumbsup: :thumbsup:
YOU ARE THE MAN!!!

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum