Tuesday, July 28, 2015

javascript to give text color code if the required value is less than the actual value

 $(document).ready(function () {
        try {
            $("input[id^=txtNumAmountToPay]").each(function () {
                if ($(this).val() != "") {
                    var arrayRemarks = $(this).attr('id').split("txtNumAmountToPay");
                    var txtAmountToPayID = 'input[id="txtNumAmountToPay' + arrayRemarks[1] + '"]';
                    var txtOpenAmountID = 'input[id="hidNumAmountToPay' + arrayRemarks[1] + '"]';
                    var txtAmountToPay = parseFloat($(txtAmountToPayID).val().replace(",", ""));
                    var txtOpenAmount = parseFloat($(txtOpenAmountID).val().replace(",", ""));

                    if (txtAmountToPay < txtOpenAmount) {
                        $(this)[0].style.backgroundColor = "yellow";
                    }
                    else {
                        $(this)[0].style.backgroundColor = "white";
                    }
                }
            });

            $("input[id^=txtNumAmountToPay]").change(function () {
                if ($(this).val() != "") {
                    var arrayRemarks = $(this).attr('id').split("txtNumAmountToPay");
                    var txtAmountToPayID = 'input[id="txtNumAmountToPay' + arrayRemarks[1] + '"]';
                    var txtOpenAmountID = 'input[id="hidNumAmountToPay' + arrayRemarks[1] + '"]';
                    var txtAmountToPay = parseFloat($(txtAmountToPayID).val().replace(",", ""));
                    var txtOpenAmount = parseFloat($(txtOpenAmountID).val().replace(",", ""));

                    if (txtAmountToPay < txtOpenAmount) {
                        $(this)[0].style.backgroundColor = "yellow";
                    }
                    else {
                        $(this)[0].style.backgroundColor = "white";
                    }
                }
            });


No comments:

Post a Comment