View Full Version : Wanting a Javascript way of navigating/linking by user entering numbers

12-18-2007, 05:41 AM
Problem as follows. I'm sure the solution is fairly straightforward; I'm a newcomer to Javascript:

I have 75 files which I want accessed from one menu link. Each file is referenced by a number, so for instance "OD_01_PC.htm" can be referred to as "01" as far as the user is concerned; "OD_02_CT.htm" can be referred to as "02", and so forth: The file names vary, but each is given a double digit integer reference number.

I could do it as a jump menu - however the menu would end up being too awkwardly long for the user to scroll through. What I want is a form field where the user can simply enter "63" for instance, and be taken to the corresponding file ("OD_63_PF.htm"), after clicking a "go" button.

I am not looking for the most efficient code. The validation need not be complicated: If the user enters anything other than 01-75 or 0-9 --- the field should simply be cleared on clicking "go". User entry of "9" should be treated the same as user entry of "09".

Any help would be much appreciated.


Philip M
12-18-2007, 08:03 AM
Here you are:-

<form name = "myform">
<input type = "text" name = "inBox" size = "2" maxlength = "2">
<input type = "button" value = "GO" onclick = "jump()">

<script type = "text/javascript">

function jump() {
val = document.myform.inBox.value;
val = parseInt(val);
if (!/\d{1,2}/.test(val)) {
alert ("Invalid Entry! Only numbers are allowed!");
document.myform.inBox.value = "";
return false;
if (val <1 || val >75) {
alert ("Invalid Entry! Must be in range 1 to 75");
document.myform.inBox.value = "";
return false;
if (val <=9) {
val = "0" + val;
val = "OD_" + val +"_CT.htm";
alert (val); // delete after testing
window.location = val;

Our advice and assistance is packaged by intellectual weight and not by volume. The contents may possibly settle in transit. E&OE