Question

I have check calculation in rows of data.

Here is my row format. enter image description here

When I have select first row of "Purchase Document". It will automaticaly fill the value in its row fields. As per shown in image.

Now In second row, when I select "Purchase Document" with same value then, I need to calculate of LPO AMT (Total Amount), Pending Amout & Amount.

Means if there Amount fill with 1000 then in second row it will not be more then 23500 (Pending Amount).

Here my code :

function doLPOamt(val) {
        var req = Inint_AJAX();
        req.onreadystatechange = function () {
            if (req.readyState==4) {
                if (req.status==200) {
                    document.getElementById('LPO_AMT').value="";
                    document.getElementById('LPO_AMT').value=req.responseText; //retuen value
                }
            }
        };
        req.open("GET", "lpoamnt.php?val="+val); //make connection
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
        req.send(null); //send value
    }

function doPendingamt(val) {
        var req = Inint_AJAX();
        req.onreadystatechange = function () {
         if (req.readyState==4) {
              if (req.status==200) {
                    document.getElementById('PENDING_AMT').value="";
                   document.getElementById('PENDING_AMT').value=req.responseText; //retuen value
              }
         }
        };
        req.open("GET", "pendingamnt.php?val="+val); //make connection
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
        req.send(null); //send value
    }

I hope you understand well

Thank you in advance

Was it helpful?

Solution

I have solved this problem.

I have just modify the code and get sollution

Here is my modified function

function doPendingamt(val,cnt) {
        var req = Inint_AJAX();
        req.onreadystatechange = function () {
         if (req.readyState==4) {
              if (req.status==200) {
                   //document.getElementById('PENDING_AMT').value="";
                   //document.getElementById('PENDING_AMT').value=req.responseText; //retuen value

                   $('input[name=PENDING_AMT['+cnt+']]').val();
                   $('input[name=PENDING_AMT['+cnt+']]').val(req.responseText);

                   var elements = document.getElementsByClassName('purshasedocscss');

                   var totalAmt = 0;
                   var pendingAmt = 0;
                   var greater = 0;
                   for(var x=0; x < elements.length; x++){
                       if(val == elements[x].value && elements[x].value != -1){
                           if(pendingAmtTmp > pendingAmt) {
                                pendingAmt = pendingAmtTmp;    
                           }
                           greater++;
                       }
                   }

                   if(greater > 1) {
                        for(var y=0; y < elements.length; y++){

                            if(val == elements[y].value && $('input[name=AMOUNT['+y+']]').val() != ''){
                                var amount      = $('input[name=AMOUNT['+y+']]').val();
                                totalAmt        = parseFloat(amount) + parseFloat(totalAmt);
                            }
                        }
                        var amt = pendingAmt - totalAmt;
                        $('input[name=PENDING_AMT['+cnt+']]').val(amt);
                   }
              }
         }
        };
        req.open("GET", "pendingamnt.php?val="+val); //make connection
        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=iso-8859-1"); // set Header
        req.send(null); //send value
    }

Thank you who have give time for this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top