Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.


JavaScript
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
Comments
ZurdoDev 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900