Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onclick ? 1

Status
Not open for further replies.

zunal2000

Technical User
Nov 6, 2002
5
US
How do have visitor to browse pages using PageID?

Visitor comes to the page, it is frame based.

On the top frame, there are previous and next buttons and mainframe has the actual page starting with PageID=5.

By clicking on the previous button mainframe shows page 4, and next button shows page 6. Remember the current page number should increase/decrease when buttons are clicked.

<a href="page.php?PageID=6" target="mainFrame">Prev</a> |

You are currently on page 5

<a href="page.php?PageID=4" target="mainFrame">Next</a>

Can you help me on this solution? Pages are in PHP...
 
well, you're going to have to know what page you are on anyway so you can do the navigation, so why not just make it part of the same page. You can take the contents of whatever's in your top frame and put it in a file: "header.php"

And include that file at the top of all your other documents.

That way you don't have to worry about targets and frames and all that nonsense.

Then, depending on what "PageID" is connected to, I would move forward to how to navigate. If you are pulling an ID of a page from a database, then you'll need to use the next/previous records (in case one of your IDs gets deleted or skipped or something).

If you using "PageID" to be like: [PageID].html, then all you need to do is:
Code:
$pageid = $_GET['PageID'];
$nextPage = $pageid + 1;
$previousPage =  $pageid - 1;

Problems with this of course are: When you get to page 1, unless you have a page 0, it will 404. Same goes for the last page.
 
Thank you for your reply. The page that is being showed in the mainframe is not mine. I do not have access to the page for modifications. The only thing I have is the URL and PageID numbers. That's the reason I had to use the frames so that I can modify the top frame to handle what to show in the mainframe.

Do you have any idea how to go about this?

 
@zunal2000

may I recap your question so that i am sure i understand?

you are framing a page where the frameset under your control but one of the frames (in which the main content resides) is not.
in a frame that is under your control, you have navigation buttons
these navigation buttons are links that reload the next and previous page in the main frame (whose content you have no control over).

if the above is true I would suggest the following as content for the navigation frame

Code:
<div>

<span id="prevbutton" >
 &nbsp;
</span>
<span id="currentpage">
 You are on page <span id="cp">1</span>
</span>
<span id="nextbutton">
</span> 
</div>
<script>
var cp = 0;
function movepage(t){
 p_elem = document.getElementById('prevbutton');
 n_elem = document.getElementById('nextbutton');
 cp_elem = document.getElementById('cp');
 switch (t){
  case ("p"):
   cp--;
  break;
  case("n"):
   cp++;
  break;
 }
 if (cp <=1) {
   p_elem.innerHTML=  "&nbsp;";
   } else {
    p_elem.innerHTML = '<a href="somecontent.php?PageID=' + (cp-1) + '" target="mainFrame" onclick="movepage(\'p\'); return true;">Previous</a>';
  }
  n_elem.innerHTML = '<a href="somecontent.php?PageID=' + (cp+1) + '" target="mainFrame" onclick="movepage(\'n\'); return true;">Next</a>';
  cp_elem.innerHTML = cp;
}
movepage("n");
</script>

i.e. the solution is more neatly done in javascript than php.
 
That's it!!!!!!!!!!

I am telling you....You're the man......It is working perfectly....

One more thing if you do not mind... How can I put a little form to let the visitor determine which page they would like to start with... There are thousands of pages and the number is increasing everyday.

Example: Visitor comes to the page, sees previous & next button which starts from page1. However visitor decides that he wants to start from page 486. So there is a little box there and he enters 486 in the box and uses previous-next links to move previous (485-484-483) or next pages (487-488-489).

Again millions of thanks for your help above.
 
no problem.
it would be neater if you were able to limit the user's choice of max page number.

Code:
<div>

<span id="prevbutton" >
 &nbsp;
</span>
<span id="currentpage">
 You are on page  (or goto) <input onBlur="movepage(this.value);" type="text" id="cp" style="width:1.5em;"/>
</span>
<span id="nextbutton">
</span>
</div>
<script>
var cp = 0;
function movepage(t){
 p_elem = document.getElementById('prevbutton');
 n_elem = document.getElementById('nextbutton');
 cp_elem = document.getElementById('cp');
 switch (t){
  case ("p"):
   cp--;
  break;
  case("n"):
   cp++;
  break;
  default:
   cp = cp_elem.value;
   parent.mainFrame.location="somecontent.php?PageID="+cp;
 }
 if (cp <=1) {
   p_elem.innerHTML=  "&nbsp;";
   } else {
    p_elem.innerHTML = '<a href="somecontent.php?PageID=' + (cp-1) + '" target="mainFrame" onclick="movepage(\'p\'); return true;">Previous</a>';
  }
  n_elem.innerHTML = '<a href="somecontent.php?PageID=' + (cp+1) + '" target="mainFrame" onclick="movepage(\'n\'); return true;">Next</a>';
  cp_elem.value= cp;
  
}
movepage("n");
</script>
 
THANK YOU....THANK YOU AND THANK YOU AGAIN....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top