Click to See Complete Forum and Search --> : IE 6 number comparison bug


tmcneer
08-12-2003, 02:34 PM
One of the simplest validations on one of my sites has suddenly developed an error - it doesn't show as an error, it just works incorrectly. This occurs in IE 6, but not Netscape. I haven't yet been able to test it on earlier IE versions, but I wonder if anyone knows about a bug that might cause this.

This is all the validation involves:

// validate Cond. Inlet vs. Outlet
if (form.two.value < form.one.value)
{
alert("The Condenser Outlet Temp. can not be less than the Condenser Inlet Temp.");
form.one.focus();
return false;
}

This operates properly until the second value reaches 100, while the first remains under 100. In other words, if the first value is 85 and the second 99, the validation works. If the first value is 85 and the second is 100, I get the alert.

After both vaues pass 100, the validation again works properly.

Anyone have any ideas?

Thanks,

Tom McNeer

pyro
08-12-2003, 02:44 PM
Can you post a link to the page that this is happening on, please?

Charles
08-12-2003, 03:08 PM
Give if (Number(form.two.value) < Number(form.one.value)) a try.

tmcneer
08-12-2003, 03:53 PM
Aha! So it was being evaluated as a string rather than a number. I see, Charles. Thanks for the explanation.

As long as I've got you -- since this seems to work differently in different browsers -- and since I've seen this sort of direct numerical comparison in many places (i.e., without the "Number()" datatype specifier) -- do you know if the syntax you quoted is a more correct way to write the statement, or simply a Microsoft implementation?

I was under the impression that Javascript would evaluate what appeared to be an integer or floating point number as a number, unless there was a real reason to convert datatypes.

Charles
08-12-2003, 04:17 PM
Originally posted by tmcneer
I was under the impression that Javascript would evaluate what appeared to be an integer or floating point number as a number, unless there was a real reason to convert datatypes. As was I. There's just no understanding those folks in Redland. And I know a few of them.

tmcneer
08-12-2003, 04:24 PM
As was I. There's just no understanding those folks in Redland. And I know a few of them.

Noted. Thanks again for the advice.


Tom