Solved

jquery if / else condition not working properly

Posted on 2011-09-26
3
261 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
Comment Utility
what if you try changing it to:

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

Accepted Solution

by:
jagssidurala earned 500 total points
Comment Utility
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
Comment Utility
try to use parseInt

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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

10 Experts available now in Live!

Get 1:1 Help Now