Solved

jquery if / else condition not working properly

Posted on 2011-09-26
3
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…

732 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