Sunday, 24 November 2013

by entering percentage on textbox it will calculate grid column percentage and add that percentage amount with that column amount and stored it to another column for every line item of the grid

function fcnDistribution() {
     // ClearValues();
     var gridrowLength = $("span[id$=lblSCAmount]").length;
     var Percentage = $("[id$='txtServiceChargePerc']").val();
     // alert("Percentage" + Percentage);
     $("span[id$=lblSCAmount]").each(function () {
         var id = $(this).attr('id');
         var rowId = id.substr(id.length - 17).substr(0, 5);
         var ScAmount = Filtervalue($(this));
         // alert("SC Amount" + ScAmount);
         // alert(parseFloat(ScAmount) +"\r\n"+ parseFloat(Percentage.replace("%", '')))
         //if()
         {

             var perCAmount = parseFloat((parseFloat(ScAmount) * parseFloat(Percentage.replace("%", ''))) / 100);
             // alert("perCAmount" + perCAmount);
             var totalamt = parseFloat(perCAmount) + parseFloat(ScAmount);
             //alert("total" + totalamt);
         }
         var txtChargeAmountId = $("[id$=" + rowId + "_txtChargeAmount]");
         //alert("txtAmountId" + txtChargeAmountId.val());
         var ChargeAmt = "$" + parseFloat(totalamt, 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString();
         txtChargeAmountId.val(ChargeAmt);
     });
 }


   function ValidatePercent() {

        var ServiceChargePerc = $("[id$='txtServiceChargePerc']");

        $(ServiceChargePerc).keydown(function (event) {
           // onlyNumbers(event);

            $(ServiceChargePerc).focusout(function (event) {
                var percent = $(ServiceChargePerc).val().replace("$", " ");

                if (percent.indexOf('%') == -1 && $(ServiceChargePerc).val().length != 0)
                    $(ServiceChargePerc).val(parseFloat(percent).toFixed(2) + "%");

            });
        });




 function Filtervalue(input) {
     var Output = input.text();
     // alert(1);
     Output = Output.replace("$", ''); //Replace  "$"(Doller) with empty string    
     Output = Output.replace(/,/g, '');   //Replace n no of ","(camas) with empty string
     return Output;
 }


------------ textbox focus out event call function
function MouseOutvalidationReceiptHeader() {

     var txtAmountReceipt = $("[id$='txtServiceChargePerc']");


     txtAmountReceipt.focusout(function () {
         if ($.trim(txtAmountReceipt.val()) != "") {
              fcnDistribution();
             ValidatePercent();
         }
     });
 }

----------call method on postback and ready

 $(document).ready(function () {
        ValidatePercent();
        WOChargesFocusOutValid();
        MouseOutvalidationReceiptHeader();
 
    });

    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_endRequest(function (s, e) {
        ValidatePercent();
        MouseOutvalidationReceiptHeader();
        $('form').dirtyForms();

    });

No comments:

Post a Comment