View Full Version : interactive page navigation ?

08-04-2005, 08:57 AM

I've set up buttons for navigating to last and previous pages. For a quick jump to one of 103 pages, I could use a drop down box, but the result is a ridiculously long list.

It would be smarter and more user-friendly to have a text box into which the user could type any number from 1-103 and click a button in order to be sent directly to the relevant page (the sort of thing you see at the bottom of the Adobe reader, where you can type in a page number and be sent straight there).

I've been trying to find something that would do this, but have not really known what to look for.

Hope someone can guide me. Thanks.


08-04-2005, 09:29 AM
Something like this?

<script type="text/javascript">
function go() {
// number of pages
var numPages = 103;

var page = parseInt(document.getElementById("page").value);
if((page !== page) || (page < 1) || (page > numPages)) {
window.alert("Page does not exist.");
document.getElementById("page").value = "";
else window.location = "page" + page + ".htm";
<input type="text" size="3" id="page"/><button onclick="go();">Go!</button>

Can you check for NaN directly like that in Javascript? In Java you need to use isNaN()...

08-04-2005, 12:37 PM
Can you check for NaN directly like that in Javascript? In Java you need to use isNaN()...Not usually, I have no idea if it will work in this case (haven't tested it) but, probably not. All that test appears to do is compare the string "page" to the string "NaN". One shortcut is to do this:

if (page!==page)as NaN is the only thing not equal to itself.

08-04-2005, 01:07 PM
Ah, thank you.

08-04-2005, 06:06 PM
Wow! It works. Thanks very much to you both.