/    Sign up×
Community /Pin to ProfileBookmark

problem with JS and <

I have a bit of JS code that looks like this–

[code]
if (userSearch != 0) {
if (mlscount < searchTotal) { var count = “Displaying ” + mlscount + ” of ” + searchTotal; } else { var count = “Displaying ” + searchTotal; }
document.getElementById(‘searchResults’).innerHTML = “<p style=’color: red;’>” + count + ” matching properties in this view.</p><p>Zoom in or move the map with your mouse for more results.</p>”; }
[/code]

Now, where you see the if (mlscount > searchTotal) is where the problem is. I have the two vars echoed out on my webpage, mlscount is equal to ’75’ and searchTotal is equal to ’20’ but the JS is still executing that if statement as–

Displaying 75 of 20

It should be showing the else as

Displaying 20

What is going on?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Feb 08.2006 — make sure you are comparing numbers and not strings...

use parseInt(variable) or parseFloat(variable)

parseInt(variable1) > parseInt(variable2)

Eric
Copy linkTweet thisAlerts:
@croakingtoadauthorFeb 08.2006 — Thank you very much, that was the problem! Cheers mate!
×

Success!

Help @croakingtoad 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...