Calculating gridview field total and displaying in footer text box using javascript
<p>I am struglling a lot to find out the total of gridview cells and displaying the values
Footer textbox. Every time I am getting the exception: Pls help me somebody whats wrong I am doing:</p>

<p>This is the exception:
<strong>Microsoft JScript runtime error: Object expected</strong>
*<em>Here is my gridview code:</em>*</p>

<pre><code> &lt;div&gt;
 &lt;asp:gridview ID="Gridview1" runat="server" ShowFooter="true" 
        onrowcommand="Gridview1_RowCommand"  AutoGenerateColumns="false" 
        CellSpacing="0" CellPadding="0" Font-Bold="false" 
        onrowdeleting="Gridview1_RowDeleting"&gt;
    &lt;Columns&gt;
  &lt;asp:BoundField DataField="RowNumber" HeaderText="Row Number"/&gt;
  &lt;asp:TemplateField HeaderText="Select" ControlStyle-Width="50px" HeaderStyle-Font-Bold="false" ControlStyle-Font-Bold="false"&gt;
 &lt;ItemTemplate&gt;
     &lt;asp:CheckBox ID="chkSelect" runat="server" Width="80px"/&gt;
 &lt;/ItemTemplate&gt;     
 &lt;/asp:TemplateField&gt;
    &lt;asp:TemplateField HeaderText="Header 1" HeaderStyle-Font-Bold="false"  ControlStyle-Font-Bold="false"&gt;
        &lt;ItemTemplate&gt;
            &lt;asp:TextBox ID="TextBox1" runat="server" Width="70px"&gt;&lt;/asp:TextBox&gt;
        &lt;/ItemTemplate&gt;            
        &lt;FooterTemplate&gt;
            &lt;asp:Label ID="lblTotal" runat="server" Text="Total" Font-Bold="true"&gt;       &lt;/asp:Label&gt;
        &lt;/FooterTemplate&gt;            
    &lt;/asp:TemplateField&gt;
    &lt;asp:TemplateField HeaderText="Header 2"  HeaderStyle-Font-Bold="false" ControlStyle-Font-Bold="false"&gt;
        &lt;ItemTemplate&gt;
            &lt;asp:TextBox ID="TextBox2" Width="70px" runat="server" onkeyup="Calculate('Gridview1')"&gt;&lt;/asp:TextBox&gt;
        &lt;/ItemTemplate&gt;            
        &lt;FooterTemplate&gt;
            &lt;asp:TextBox ID="total" runat="server" Width="70px"&gt;&lt;/asp:TextBox&gt;
        &lt;/FooterTemplate&gt;            
    &lt;/asp:TemplateField&gt;
    &lt;asp:TemplateField HeaderText="Header 3" HeaderStyle-Font-Bold="false" ControlStyle-Font-Bold="false"&gt;
        &lt;ItemTemplate&gt;
             &lt;asp:TextBox ID="TextBox3" Width="70px" runat="server" &gt;&lt;/asp:TextBox&gt;
        &lt;/ItemTemplate&gt;
        &lt;FooterStyle HorizontalAlign="Right" /&gt;
        &lt;FooterTemplate&gt;
         &lt;asp:Button ID="ButtonAdd" runat="server" Text="Add New Row" CommandName="AddNewRow" /&gt;
        &lt;/FooterTemplate&gt;
    &lt;/asp:TemplateField&gt;
    &lt;/Columns&gt;
  &lt;/asp:gridview&gt;   
  &lt;/div&gt;
</code></pre>

<p>Here is my JavaScript code:</p>

<pre><code>   &lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.5.js"&gt;&lt;/script&gt;  
&lt;script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"&gt;&lt;/script&gt; 
&lt;script type="text/javascript"&gt;  
function Calculate(GridView)
{
   var total = 0;   
   var gridview = document.getElementById('&lt;%=Gridview1.ClientID %&gt;').getElementsByTagName("input");        
   for ( i = 0; i &lt; gridview.rows.length; i ++)
   {
       var node = gridview.rows[i].cells[3].childNodes[3]; //textbox  

       if (node != undefined &amp;&amp; node.type == "text") //check only textbox, ignore empty one
            if (!isNaN(node.value) &amp;&amp; node.value != "") //check for valid number
               total += parseInt(node.value); 
   }       
  // document.getElementById("total").innerHTML = total.toString(); //display
   var gridview1 = document.getElementById('&lt;%=grdview1.ClientID %&gt;');
   gridview1.rows[gridview.rows.length -1].cells[0].innerHTML=total;

}
</code></pre>

<p>  </p>

<p>I had tried with many ways but every time getting the same exception:
Microsoft JScript runtime error: Object expected</p>

<p>It seems something wrong with my JavaScript code..pls somebody and help me out.</p>
