Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2007
    Thanked 0 Times in 0 Posts

    Wanting a Javascript way of navigating/linking by user entering numbers

    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.


  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,704 Times in 2,680 Posts
    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
    Last edited by Philip M; 12-18-2007 at 02:33 PM. Reason: improved


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts