/    Sign up×
Community /Pin to ProfileBookmark

IE 6 number comparison bug

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

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@pyroAug 12.2003 — Can you post a link to the page that this is happening on, please?
Copy linkTweet thisAlerts:
@CharlesAug 12.2003 — [font=georgia]Give [font=monospace]if (Number(form.two.value) < Number(form.one.value))[/font] a try.[/font]
Copy linkTweet thisAlerts:
@tmcneerauthorAug 12.2003 — 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.
Copy linkTweet thisAlerts:
@CharlesAug 12.2003 — [i]Originally posted by tmcneer [/i]

[B]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. [/B][/QUOTE]
[font=georgia]As was I. There's just no understanding those folks in Redland. And I know a few of them.[/font]
Copy linkTweet thisAlerts:
@tmcneerauthorAug 12.2003 — 
[B][font=georgia]As was I. There's just no understanding those folks in Redland. And I know a few of them.[/font] [/B][/QUOTE]


Noted. Thanks again for the advice.


Tom
×

Success!

Help @tmcneer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...