Click here to Skip to main content
13,046,176 members (69,066 online)
Rate this:
 
Please Sign up or sign in to vote.
Hi guys, i am having trouble in calculation in grid, i made function but it works only on 1st row of grid and calculate total of first row of grid and then show this value in grand total textbox too. I want to do the same on all 4 rows of grid, what do i do? Kindly help.


function CalculateTotal() {
                var Gtot = 0;
                
                var RowCount = 0;
                //var RowCount = document.getElementById('<%= hfGrdRows.ClientID%>').value - 0;
                //alert(RowCount);
                var grid = document.getElementById('<%= Grd_Exams.ClientID%>');
                for (var i = 1; i < grid.rows.length ; i++) {
 
                        var cell = grid.rows[i].cells;
                        //var HTML = cell[0].innerHTML;
                        
                            var Participation = document.getElementById('txtCl_Part').value - 0;
                            
                            var Assgnmnt = document.getElementById('txtAssgnmnt').value - 0;
                            var Quiz = document.getElementById('txtQuiz').value - 0;
                            var WrPaper = document.getElementById('txtWP').value - 0;
                            var OSME = document.getElementById('txtOSME').value - 0;
                            //for (var i = 1; i < grdLength - 1; i++) {
 
                            var Total = parseFloat(Participation) + parseFloat(Assgnmnt) + parseFloat(Quiz) + parseFloat(WrPaper) + parseFloat(OSME);
                            if (!isNaN(Total)) {
                                document.getElementById('txtTotal').value = Total;
                            }
                            else {
                                alert("Nikal");
                            }
                        }
                    var getTotal = document.getElementById('txtTotal').value - 0;
                    var Gtot = parseInt(Gtot) + parseFloat(getTotal);
                    if (!isNaN(Gtot)) {
                        document.getElementById('txtGTot').value = Gtot;
                    }
 
                    else {
                        alert("Cannot Show Total");
                    }
 
                    var Percentage = (parseFloat(Gtot) * 100) / 400;
 
                    if (!isNaN(Percentage)) {
                        document.getElementById('txtPercent').value = Percentage;
                    }
                    else {
                        alert("Cannot show percentage");
                    }
            }
Posted 21-Jul-14 12:02pm
Comments
RyanDev 21-Jul-14 19:43pm
   
Where are you stuck?
Muhammad Bilal Khan 22-Jul-14 10:53am
   
RyanDev i mentiioned where i stuck. My function work fine for grid's first row but i want to done same with all row. What shoul di do ?
Muhammad Bilal Khan 22-Jul-14 10:57am
   
DamithSL thanks for ur reference but i want to do it from javascript. Any help regarding this?
thatraja 4-Sep-14 6:02am
   
jQuery is better than javascript

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 21 Jul 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100