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 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Comparing numeric variables in Javascript

    Hi there,

    I seem to have a problem comparing numeric values in javascript, basically 2 numbers are supplied via a form, and on submit I need them to validate these to ensure that the second number is always larger than the first! This works fine with 1 digit numbers, however as soon as one of them are 2 digit, for example 8 and 12, it seems to think 8 is larger than 12, as though it is only maybe looking at the first digit?? Please could someone help as I am completely confused...

    So you may see, the code is : if (sleepsFrom.value > sleepsTo.value) {

    Your help would be sooo much appreciated!! )

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Did you parseFloat() or parseInt() the values before comparing them?


  •  

    Posting Permissions

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