Calculating total of 7th column of my table-->NaN

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KUTTAN
    New Member
    • Mar 2007
    • 33

    Calculating total of 7th column of my table-->NaN

    i want to total of all 7th columns(in all rows) of my table

    my tables id is ctl00_ContentPl aceHolder1_Quot e1_RadGdProduct List_ctl01

    The first row of the table is headings

    the following code works fine in IE7
    But I am getting 'NaN' when i use Mozilla

    i found that
    [i]var rowTotal=Number (table.rows.cel ls[7].firstChild.val ue);

    is causing problem
    what should i use to do this that do work in Mozilla and fire fox atlest

    I don't know much javascript

    my code is bellow
    ............... ............... ............... .......
    [CODE=javascript]function doSubTotal(c){
    var subTotal=0;
    table=document. getElementById( 'ctl00_ContentP laceHolder1_Quo te1_RadGdProduc tList_ctl01');

    for(var i=1;i<table.row s.length;i++){

    var rowTotal=Number (table.rows[i].cells[7].firstChild.val ue);
    subTotal=eval(s ubTotal)+eval(r owTotal);

    }

    document.getEle mentById('ctl00 _ContentPlaceHo lder1_Quote1_Tx tBxSubTotal').v alue=subTotal;

    }[/CODE]
    ............... ............... ............... ............... ............... ...
    Last edited by gits; Oct 12 '07, 09:10 AM. Reason: added code tags
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    Originally posted by KUTTAN
    i want to total of all 7th columns(in all rows) of my table

    my tables id is ctl00_ContentPl aceHolder1_Quot e1_RadGdProduct List_ctl01

    The first row of the table is headings

    the following code works fine in IE7
    But I am getting 'NaN' when i use Mozilla

    i found that
    [i]var rowTotal=Number (table.rows.cel ls[7].firstChild.val ue);

    is causing problem
    what should i use to do this that do work in Mozilla and fire fox atlest

    I don't know much javascript

    my code is bellow
    ............... ............... ............... .......
    function doSubTotal(c){
    var subTotal=0;
    table=document. getElementById( 'ctl00_ContentP laceHolder1_Quo te1_RadGdProduc tList_ctl01');

    for(var i=1;i<table.row s.length;i++){

    var rowTotal=Number (table.rows[i].cells[7].firstChild.val ue);
    subTotal=eval(s ubTotal)+eval(r owTotal);

    }

    document.getEle mentById('ctl00 _ContentPlaceHo lder1_Quote1_Tx tBxSubTotal').v alue=subTotal;

    }
    ............... ............... ............... ............... ............... ...
    [code=javascript]
    var rowTotal=Number (table.rows[i].cells[7].firstChild.val ue);
    [/code]

    What is "Number" here?
    And need not to use "eval" if you convert it into number already.
    You can also try this .........

    [code=javascript]
    for(var i=1;i<table.row s.length;i++){
    var rowTotal=parseI nt(table.rows[i].cells[7].firstChild.val ue);
    subTotal=subTot al+rowTotal;
    }
    [/code]

    Debasis Jana

    Comment

    • KUTTAN
      New Member
      • Mar 2007
      • 33

      #3
      i have done
      alert("..."+tab le.rows[i].cells[7].firstChild.val ue);

      it is the correct number for IE
      but
      this is undefined for Mozilla

      I have also tried parseFloat ,parseInt
      nothing good happned
      ;(

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by KUTTAN
        i have done
        alert("..."+tab le.rows[i].cells[7].firstChild.val ue);

        it is the correct number for IE
        but
        this is undefined for Mozilla

        I have also tried parseFloat ,parseInt
        nothing good happned
        ;(
        So you are using Mozilla.

        Use ..............
        [code=javascript]
        alert("..."+tab le.rows[i].childNodes[7].firstChild.val ue);
        [/code]

        Debasis Jana

        Comment

        • KUTTAN
          New Member
          • Mar 2007
          • 33

          #5
          [HTML]<table style="width: 100%; border-collapse: collapse; empty-cells: show;" border="0" cellspacing="0" >
          <colgroup>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          <col>
          </colgroup>
          <thead>
          <tr>
          <th > Code</th><th >Brand</th><th>Product Name</th><th >Remarks</th><th >Unit</th><th class="GridHead er_Default">Qty </th><th class="GridHead er_Default">Uni t Price</th><th class="GridHead er_Default">Tot al</th><th class="GridHead er_Default">Cos t</th><th >Stock Position</th><th >Source</th>
          </tr>
          </thead><tbody>
          <tr >
          <td>)A1</td><td>Techno Flex</td><td>
          <input name="ctl00TxtB xProductName" value="100x6x16 " id="ctl00TxtBxP roductName" class="RadTextB ox3" type="text">
          </td><td>
          <input name="ctl00TxtB xRemarks" id="ctl00TxtBxR emarks" class="RadTextB ox3" type="text">
          </td><td>
          <select name="ctl00DdlU nit" id="ctl00DdlUni t">
          <option selected="selec ted" value="0"> </option>
          <option value="1">Litte r</option>

          </select>
          </td><td>
          <input name="ctl00TxtB xQuantity" value="1" id='ctl00TxtBxQ uantity' type="text">
          </td><td>
          <input name="ctl00TxtB xPrice" value="0.00" id="ctl00TxtBxP rice" type="text">
          </td><td>
          <input name="ctl00TxtB xRowTotal" value="0.00" id="ctl00TxtBxR owTotal" type="text" >&nbsp;
          </td><td>
          <input name="ctl00TxtB xCost" value="0" id="ctl00TxtBxC ost" type="text">&nb sp;
          </td><td>
          <input name="ctl00TxtB xSource" id="ctl00TxtBxS ource" type="text">
          </td>
          </tr>
          </tbody>

          </table>[/HTML]

          this is my table structure
          my table structure is the problem ,there is a tbody
          Last edited by gits; Oct 12 '07, 09:11 AM. Reason: added code tags

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Did you use my code?

            Debasis Jana.

            Comment

            • KUTTAN
              New Member
              • Mar 2007
              • 33

              #7
              Originally posted by dmjpro
              Did you use my code?

              Debasis Jana.
              alert("..."+tab le.rows[i].childNodes[7].firstChild.val ue);
              this is undefined in Mozilla
              but ok in IE
              my table has tbody thead etc is it a problem?

              Comment

              • dmjpro
                Top Contributor
                • Jan 2007
                • 2476

                #8
                Originally posted by KUTTAN
                alert("..."+tab le.rows[i].childNodes[7].firstChild.val ue);
                this is undefined in Mozilla
                but ok in IE
                my table has tbody thead etc is it a problem?
                I think so .. though I am not sure about that.
                So have the reference of "TBODY" then try with ....

                [code=javascript]
                tbody.chidlNode s[i].childNodes[7].firstChild.val ue
                [/code]

                Debasis Jana

                Comment

                • gits
                  Recognized Expert Moderator Expert
                  • May 2007
                  • 5390

                  #9
                  heya kuttan,

                  please use code tags when posting source-code ... for example:

                  &#91;CODE=javas cript] your code here [/CODE]

                  kind regards

                  Comment

                  Working...