Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question submit numbers in edit box to HTML page???

    Hello all..

    Can any one help me to write a javascript that when some one type in the numbers such as 1915, and it will go to 1915.html?

    I want the people have to type 4 digits numbers, and only accept from 1920 to 2040 only! Other numbers such as 1900 will popup a messages and said "No Numbers Found or something like that"..

    Can any one do that, like with a edit box with the submit button?

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <html>
    <head>
    <script language="javascript">
    function check(){
    no=document.f.num.value;
    if (!isNaN(no)){
    no = parseInt(no,10);
    if (no>=1920 && no<=2040){
    location.href=no+".html";
    return;
    }
    }
    alert("Please type a number between 1920 to 2040.");
    document.f.num.focus();
    document.f.num.select();
    }
    </script>
    </head>
    <body>
    <form name="f">
    Please enter a 4-digit number:
    <input name="num" maxlength="4"><br>
    <input type="button" value="Open" onclick="check()">
    </form>
    </body>
    </html>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx glenngv, that works!

    I have one more question..

    How do I make it go to a folder then num.html such as folder/1921.html


    location.href=cfolder/+no+".html";
    That will get a NaN.html when press Open

    location.href=folder/ no+".html";
    same thing..

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    location.href="folder/"+no+".html";
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    thank you. it works
    TT

  • #6
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a way I can insert it in a CSS or so when I edit it in the css file. IT will be works on all my html pages.

    All I need is to put this.. and it will show the above HTML:
    <link href="filename.css" rel="stylesheet">

    I know it something like that. but I don't know how to say it...

    Please help me...
    TT

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    since you will use it to some of your pages, i edited it so that it will be generic:

    save it in a separate file with extension .js (don't include script tag)

    function check(objNo){
    no=objNo.value;
    if (!isNaN(no)){
    no = parseInt(no,10);
    if (no>=1920 && no<=2040){
    location.href=no+".html";
    return;
    }
    }
    alert("Please type a number between 1920 to 2040.");
    objNo.focus();
    objNo.select();
    }




    then in your html pages:
    <html>
    <head>
    <script language="javascript" src="validation.js"></script>
    </head>
    <body>
    <form>
    <input name="num" maxlength="4"><br>
    <input type="button" value="Open" onclick="check(this.form.num)">
    </form>
    </body>
    </html>

    change validation.js to the name of your js file and num to appropriate name of textbox.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #8
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It works, but I need it to target my html file into a directory/folder
    location.href=folder/"+no+".html;
    I will get -1.#IND.

    location.href="folder/"+no+".html;
    I will get error..

    TT

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    i thought this already works:
    location.href="folder/"+no+".html";

    or do you mean like this:
    location.href="directory/folder/"+no+".html";



    Originally posted by doubleT
    It works, but I need it to target my html file into a directory/folder
    location.href=folder/"+no+".html;
    I will get -1.#IND.

    location.href="folder/"+no+".html;
    I will get error..

    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It is already works for one page, but inside the filename.js won't work I use those codes..
    TT

  • #11
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Originally posted by doubleT
    It is already works for one page, but inside the filename.js won't work I use those codes..
    can you post the html and js codes?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #12
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here is the HTML...
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>Student Section</title>
    <link href="main_files/style.css" rel="stylesheet">
    <script language="javascript" src="classmates/classmate.js"></script>
    </head>
    <body>
    <form>
    <p align="center">&nbsp;
    <input name="num" maxlength="4" size="10" style="background-color:#FFCC00" style="color:#0000FF"><input type="button" value="GO" onclick="check(this.form.num)" style="background-color:#0000FF" style="color:#FFFF00">
    <br>
    </form></body>
    </html>

    Here is the JS file...


    function check(objNo){
    no=objNo.value;
    if (!isNaN(no)){
    no = parseInt(no,10);
    if (no>=1910 && no<=2049){
    location.href="classmates/"+no+".html;
    return;
    }
    }
    alert("Input year from 1910 to 2049");
    objNo.focus();
    objNo.select();
    }
    TT

  • #13
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    can you also post the directory structure of all your pages, like where the 1910-2049.html pages are, the .js files, etc
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #14
    New Coder
    Join Date
    Jul 2002
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All mine HTML and js file are in the classmates folder..
    TT

  • #15
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    if your html and js files are all in the classmates folder, then you should not have specified the classmates folder in the script tag and in location.href. It should be these:

    <script language="javascript" src="classmate.js"></script>

    location.href=+no+".html;
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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