View Full Version : Comparing numeric variables in Javascript

03-10-2005, 09:59 PM
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!! :o)

03-10-2005, 10:13 PM
Did you parseFloat() or parseInt() the values before comparing them?