Solved

jquery if / else condition not working properly

Posted on 2011-09-26
3
262 Views
Last Modified: 2012-05-12
I am unable to wrap my head around this, because from what i can tell, this should be working... It is possible that my syntax is incorrect, but the same syntax is working properly on other areas of the page that call this same js function:

            $(":submit[value='add']").click(function (e) {
                e.preventDefault();
                var $r = $(this).closest("td").prev("td").find("span").text();
                var $h = $(this).closest("tr").find("input:hidden:eq(0)").val();
                var $t = $(this).closest("td").next("td").find(":text");

                if ($r <= $h) {
                    $t.val($r);
                    $(this).closest("tr").prevAll("tr[class^='headerrow']:first").find("td").css("background-color", "#F5F500");
                    $(this).closest("tr").prevAll("tr[class^='headerrow']:first").find("td").css("color", "#333");
                }
                if ($r > $h) {
                    $t.val($h);
                    $(this).closest("tr").prevAll("tr[class^='headerrow']:first").find("td").css("background-color", "#555");
                    $(this).closest("tr").prevAll("tr[class^='headerrow']:first").find("td").css("color", "#CCC");
                }

            })

Open in new window


What gives?
is my syntax incorrect?

[see the screen shot below]

 screenshot
0
Comment
Question by:jsvb1977
3 Comments
 
LVL 32

Expert Comment

by:Big Monty
ID: 36601111
what if you try changing it to:

if ($r.val() <= $h.val() ) {
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 36601119
Its doing string comparison.

If we consider strings 112 is less than 13........

so you have to use parseInt method

if (parseInt($r) <= parseInt($h))
{


}
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36601126
try to use parseInt

if (parseInt($r) <= parseInt($h)) {
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now