Solved

jquery if / else condition not working properly

Posted on 2011-09-26
3
264 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 33

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
html input 8 42
suddenly angular cli doesn't work. 5 38
xjs: how to get sum of value in for loop 2 18
ASP.NET MVC - Views 3 17
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

840 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