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 6 of 6

Thread: Validation

  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Validation

    I can not get this code to work it does not seem to do any thing.
    I aint sure what the problem is

    <html>
    <head>
    <title>Route Planner</title>

    <script language="JavaScript" type="text/JavaScript">

    function validateNumber(b) {
    var n = b.value*1;
    return (n >= 1 && n <= 3);
    }

    function validateTime(b) {
    var t = b.value;
    var t_array = t.split(".");

    var hour = t_array[0]*1;
    var mins = t_array[1]*1;

    return(hour >= 0 && hour <= 23 && mins >= 0 && mins <= 59);
    }

    function validateBoxes() {
    if(!validateNumber(numBox)) {
    alert("Bad Number");
    }

    if(!validateTime(timeBox)) {
    alert("Bad Time");
    }
    }

    </script>
    </head>
    <body>

    <form>
    <input type="text" name="numBox" id="numBox"/>
    <input type="text" name="timeBox" id="timeBox"/>
    <input name="button" type=button onClick="validateBoxes"/>
    </form>

    </body>
    </html>

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Bad call of the function:

    Code:
    <input name="button" type=button onClick="validateBoxes()"/>
    Of course once you fix that you'll find that the validateBoxes function is also broken:

    Code:
    function validateBoxes() {
    if(!validateNumber(document.getElementById('numBox'))) {
    alert("Bad Number");
    }
    
    if(!validateTime((document.getElementById('timeBox'))) {
    alert("Bad Time");
    }
    }
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it still dont work i dont know what is wrong

    <html>
    <head>
    <title>Route Planner</title>

    <script language="JavaScript" type="text/JavaScript">

    function validateNumber(b) {
    var n = b.value*1;
    return (n >= 1 && n <= 3);
    }

    function validateTime(b) {
    var t = b.value;
    var t_array = t.split(".");

    var hour = t_array[0]*1;
    var mins = t_array[1]*1;

    return(hour >= 0 && hour <= 23 && mins >= 0 && mins <= 59);
    }

    function validateBoxes() {
    if(!validateNumber(document.getElementById('numBox')) {
    alert("Bad Number");
    }

    if(!validateTime(document.getElementById('timeBox')) {
    alert("Bad Time");
    }
    }

    </script>
    </head>
    <body>
    <p>

    <form>
    <input type="text" name="numBox" id="numBox"/>
    <input type="text" name="timeBox" id="timeBox"/>
    <input name="button" type=button onClick="validateBoxes()"/>
    </form>

    </body>
    </html>

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You left off one ")" character in each of those modified lines in your validateBoxes function. You have three "(" characters but only two ")" which is obviously invalid.

    Do this, On the IE Menu bar: "Tools > Internet Options > Advanced", check the box labeled "Display a notification about every script error".

    If you're working with scripts it's pretty much mandatory that you be informed about script errors so you'll know they exist and can hunt them down. Otherwise you get a tiny little icon on the status bar telling you there was a problem and that icon is pretty easy to miss.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Feb 2004
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for your time that solved my problem
    took ur advice enableded the debugger

  • #6
    Regular Coder
    Join Date
    Jul 2003
    Location
    Massachusetts
    Posts
    472
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by dips_007
    enableded the debugger
    If you'd even call it that. I don't particularly find random or otherwise inaccurate error messages helpful.

    What you actually want to do is get yourself a real browser and take advantage of its excellent JavaScript debugging tools (among other things) such as the JavaScript console, and of course the complete JavaScript debugging enviorment: Venkman.


  •  

    Posting Permissions

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