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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Location
    England
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    But it really is false

    I have a validation function which compares two values, startsecs and endsecs. If startsecs is greater than endsecs, an error should be displayed, but it's not working because the if statement is evaluating as true, when it should be false.

    You can see this by going to link removed, uncheck the box that says 'this event last all day', then enter 12:00 as the start time and 17:00 as the end time, and click save. Evevn in the error that's displayed, the second value is greater than the first, so it should evaluate as false.

    The function can be seen at link removed on line 223.
    Code:
            var startsecs = (document.getElementById('starthour').value * 60) + document.getElementById('startminute').value;
            var endsecs = (document.getElementById('endhour').value * 60) + document.getElementById('endminute').value;
            if(startsecs > endsecs) {
                document.getElementById('error_end').innerHTML = 'End time must be after start time:'+endsecs+'::'+startsecs;
                document.getElementById('error_end').style.display = 'block';
                valid = false;
            }
    Last edited by Echilon; 02-22-2007 at 03:47 PM. Reason: Links removed

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Anytime you're using a .value of something as a number, you need a parseInt or parseFloat. Otherwise, it's text and you get fun results with things.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New to the CF scene
    Join Date
    Feb 2007
    Location
    England
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Problem solved. Thanks for the help.

    For anyone that's interested, I needed to multiple the second .value by 1, which forced it's type to an integer.


  •  

    Posting Permissions

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