By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

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

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

my tables id is ctl00_ContentPlaceHolder1_Quote1_RadGdProductList_ 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.cells[7].firstChild.value);

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
.................................................. ..
Expand|Select|Wrap|Line Numbers
  1. function doSubTotal(c){
  2. var subTotal=0;
  3. table=document.getElementById('ctl00_ContentPlaceHolder1_Quote1_RadGdProductList_ctl01');
  4.  
  5. for(var i=1;i<table.rows.length;i++){
  6.  
  7. var rowTotal=Number(table.rows[i].cells[7].firstChild.value);
  8. subTotal=eval(subTotal)+eval(rowTotal);
  9.  
  10. }
  11.  
  12. document.getElementById('ctl00_ContentPlaceHolder1_Quote1_TxtBxSubTotal').value=subTotal;
  13.  
  14. }
.................................................. ............................
Oct 12 '07 #1
Share this Question
Share on Google+
8 Replies


dmjpro
100+
P: 2,476
i want to total of all 7th columns(in all rows) of my table

my tables id is ctl00_ContentPlaceHolder1_Quote1_RadGdProductList_ 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.cells[7].firstChild.value);

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_ContentPlaceH older1_Quote1_RadGdProductList_ctl01');

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

var rowTotal=Number(table.rows[i].cells[7].firstChild.value);
subTotal=eval(subTotal)+eval(rowTotal);

}

document.getElementById('ctl00_ContentPlaceHolder1 _Quote1_TxtBxSubTotal').value=subTotal;

}
.................................................. ............................
Expand|Select|Wrap|Line Numbers
  1. var rowTotal=Number(table.rows[i].cells[7].firstChild.value);
  2.  
What is "Number" here?
And need not to use "eval" if you convert it into number already.
You can also try this .........

Expand|Select|Wrap|Line Numbers
  1. for(var i=1;i<table.rows.length;i++){
  2. var rowTotal=parseInt(table.rows[i].cells[7].firstChild.value);
  3. subTotal=subTotal+rowTotal;
  4. }
  5.  
Debasis Jana
Oct 12 '07 #2

P: 33
i have done
alert("..."+table.rows[i].cells[7].firstChild.value);

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

I have also tried parseFloat ,parseInt
nothing good happned
;(
Oct 12 '07 #3

dmjpro
100+
P: 2,476
i have done
alert("..."+table.rows[i].cells[7].firstChild.value);

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 ..............
Expand|Select|Wrap|Line Numbers
  1. alert("..."+table.rows[i].childNodes[7].firstChild.value);
  2.  
Debasis Jana
Oct 12 '07 #4

P: 33
[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="GridHeader_Default">Qty</th><th class="GridHeader_Default">Unit Price</th><th class="GridHeader_Default">Total</th><th class="GridHeader_Default">Cost</th><th >Stock Position</th><th >Source</th>
</tr>
</thead><tbody>
<tr >
<td>)A1</td><td>Techno Flex</td><td>
<input name="ctl00TxtBxProductName" value="100x6x16" id="ctl00TxtBxProductName" class="RadTextBox3" type="text">
</td><td>
<input name="ctl00TxtBxRemarks" id="ctl00TxtBxRemarks" class="RadTextBox3" type="text">
</td><td>
<select name="ctl00DdlUnit" id="ctl00DdlUnit">
<option selected="selected" value="0"> </option>
<option value="1">Litter</option>

</select>
</td><td>
<input name="ctl00TxtBxQuantity" value="1" id='ctl00TxtBxQuantity' type="text">
</td><td>
<input name="ctl00TxtBxPrice" value="0.00" id="ctl00TxtBxPrice" type="text">
</td><td>
<input name="ctl00TxtBxRowTotal" value="0.00" id="ctl00TxtBxRowTotal" type="text" >&nbsp;
</td><td>
<input name="ctl00TxtBxCost" value="0" id="ctl00TxtBxCost" type="text">&nbsp;
</td><td>
<input name="ctl00TxtBxSource" id="ctl00TxtBxSource" type="text">
</td>
</tr>
</tbody>

</table>[/HTML]

this is my table structure
my table structure is the problem ,there is a tbody
Oct 12 '07 #5

dmjpro
100+
P: 2,476
Did you use my code?

Debasis Jana.
Oct 12 '07 #6

P: 33
Did you use my code?

Debasis Jana.
alert("..."+table.rows[i].childNodes[7].firstChild.value);
this is undefined in Mozilla
but ok in IE
my table has tbody thead etc is it a problem?
Oct 12 '07 #7

dmjpro
100+
P: 2,476
alert("..."+table.rows[i].childNodes[7].firstChild.value);
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 ....

Expand|Select|Wrap|Line Numbers
  1. tbody.chidlNodes[i].childNodes[7].firstChild.value
  2.  
Debasis Jana
Oct 12 '07 #8

gits
Expert Mod 5K+
P: 5,390
heya kuttan,

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

[CODE=javascript] your code here [/code]

kind regards
Oct 12 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.