BillyBoB6969
03-10-2009, 04:38 AM
I am building a Blog system for a school project and am putting a lot of dynamic abilities into it. One feature is that it must stay on the same page without reloading. As you could imagine there must be some sort of navigation system built. I have built one but am struggling to get it to work correctly.
This site is at My Site (http://dreamshowstudios.net/development/Blog/index.php).
The first navigation is built by the php page at the start of the browsing. When you click on new page it opens fine and then deletes all navigation. After that javascript takes the building process over. Rebuilds the system based on the CurPage variable set at the beginning and every page change.
When you click one of these built from javascript it takes you to the page you selected plus two (ex: click 3 and it brings you to 5), but the previous arrow works fine....
I have no idea where to start on fixing this problem. Any help is greatly appreciated.
var CurPage = 0;
function changeNav(EntryCount) {
var navObj = document.getElementById('Navigation');
clearObj(navObj);
if(CurPage>=2) {
if(CurPage==2) {
var anchorPre = document.createElement("a");
anchorPre.onmousedown = function() {
changePage('1', EntryCount);
return false;
}
anchorPre.appendChild(document.createTextNode("< "));
navObj.appendChild(anchorPre);
}else{
var anchorF = document.createElement("a");
anchorF.onmousedown = function() {
changePage('1', EntryCount);
return false;
}
anchorF.appendChild(document.createTextNode("First "));
navObj.appendChild(anchorF);
var anchorPre = document.createElement("a");
anchorPre.onmousedown = function() {
changePage(CurPage-1, EntryCount);
return false;
}
anchorPre.appendChild(document.createTextNode("< "));
navObj.appendChild(anchorPre);
}
}
var sPage = parseInt(CurPage)-2;
if(sPage<=0) sPage = 1;
var lPage = parseInt(CurPage)+2;
if(lPage>=Math.ceil(parseInt(EntryCount)/5)) lPage = Math.ceil(parseInt(EntryCount)/5);
var cPage = sPage;
while(cPage<=lPage) {
var anchorI = document.createElement("a");
if(cPage!=CurPage) {
anchorI.onmousedown = function() {
changePage(cPage, EntryCount);
return false;
}
}
if(cPage==CurPage)
anchorI.style.color = "#b5cade";
anchorI.appendChild(document.createTextNode(cPage+" "));
navObj.appendChild(anchorI);
cPage++;
}
}
function changePage(PageNumber, EntryCount) {
if(CurPage == 0) {
var i = 0;
while(i<=5) {
i++;
hideEntry(i);
}
var startPoint = ((PageNumber-1)*5)+1;
var endPoint = startPoint+4;
var j = startPoint;
while(j<=endPoint) {
if(j<=EntryCount) {
showEntry(j);
}
j++;
}
}else{
var HstartPoint = ((CurPage-1)*5)+1;
var HendPoint = HstartPoint+4;
var h = HstartPoint;
while(h<=HendPoint) {
if(h<=EntryCount) {
hideEntry(h);
}
h++;
}
var startPoint = ((PageNumber-1)*5)+1;
var endPoint = startPoint+4;
var j = startPoint;
while(j<=endPoint) {
if(j<=EntryCount) {
showEntry(j);
}
j++;
}
}
CurPage = PageNumber;
changeNav(EntryCount);
}
This is the important javascript for these functions.
This site is at My Site (http://dreamshowstudios.net/development/Blog/index.php).
The first navigation is built by the php page at the start of the browsing. When you click on new page it opens fine and then deletes all navigation. After that javascript takes the building process over. Rebuilds the system based on the CurPage variable set at the beginning and every page change.
When you click one of these built from javascript it takes you to the page you selected plus two (ex: click 3 and it brings you to 5), but the previous arrow works fine....
I have no idea where to start on fixing this problem. Any help is greatly appreciated.
var CurPage = 0;
function changeNav(EntryCount) {
var navObj = document.getElementById('Navigation');
clearObj(navObj);
if(CurPage>=2) {
if(CurPage==2) {
var anchorPre = document.createElement("a");
anchorPre.onmousedown = function() {
changePage('1', EntryCount);
return false;
}
anchorPre.appendChild(document.createTextNode("< "));
navObj.appendChild(anchorPre);
}else{
var anchorF = document.createElement("a");
anchorF.onmousedown = function() {
changePage('1', EntryCount);
return false;
}
anchorF.appendChild(document.createTextNode("First "));
navObj.appendChild(anchorF);
var anchorPre = document.createElement("a");
anchorPre.onmousedown = function() {
changePage(CurPage-1, EntryCount);
return false;
}
anchorPre.appendChild(document.createTextNode("< "));
navObj.appendChild(anchorPre);
}
}
var sPage = parseInt(CurPage)-2;
if(sPage<=0) sPage = 1;
var lPage = parseInt(CurPage)+2;
if(lPage>=Math.ceil(parseInt(EntryCount)/5)) lPage = Math.ceil(parseInt(EntryCount)/5);
var cPage = sPage;
while(cPage<=lPage) {
var anchorI = document.createElement("a");
if(cPage!=CurPage) {
anchorI.onmousedown = function() {
changePage(cPage, EntryCount);
return false;
}
}
if(cPage==CurPage)
anchorI.style.color = "#b5cade";
anchorI.appendChild(document.createTextNode(cPage+" "));
navObj.appendChild(anchorI);
cPage++;
}
}
function changePage(PageNumber, EntryCount) {
if(CurPage == 0) {
var i = 0;
while(i<=5) {
i++;
hideEntry(i);
}
var startPoint = ((PageNumber-1)*5)+1;
var endPoint = startPoint+4;
var j = startPoint;
while(j<=endPoint) {
if(j<=EntryCount) {
showEntry(j);
}
j++;
}
}else{
var HstartPoint = ((CurPage-1)*5)+1;
var HendPoint = HstartPoint+4;
var h = HstartPoint;
while(h<=HendPoint) {
if(h<=EntryCount) {
hideEntry(h);
}
h++;
}
var startPoint = ((PageNumber-1)*5)+1;
var endPoint = startPoint+4;
var j = startPoint;
while(j<=endPoint) {
if(j<=EntryCount) {
showEntry(j);
}
j++;
}
}
CurPage = PageNumber;
changeNav(EntryCount);
}
This is the important javascript for these functions.