codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  totaling textboxes  blkskull at 19:47 on Wednesday, December 13, 2006
 

I'm doing a school project and I'm trying to add up several text boxes, however some of them are blank and when I calculate them I get a NaN result. Here is my code:

qty1= parseFloat(document.form1.qty_prt.value)
qty2= parseFloat(document.form1.qty_mon.value)
qty3= parseFloat(document.form1.qty_comp.value)
sub_tot=parseFloat(document.form1.subt.value)
tax_tot=parseFloat(document.form1.tax.value)
grand_tot=parseFloat(document.form1.grandt.value)
qty_tot=eval(qty1+qty2+qty3)
alert("quantity is " + qty_tot)


  Re: totaling textboxes  dhanalakshmi at 10:32 on Friday, December 15, 2006
 

Draw the text boxes inside a for loop or wat ever method is convinient for u such that all textboxes id should start with the same text and end with the number as it is incremented in the loop.
for(int i=0;i<10;i++){
out.println("<input type='text' id='text+i' >");
}

Then in java script calculate the values as:

function addAllTextBoxValues(){
var total;
for(i=0;i<10;i++){
var txtid = text+i;
total += document.getElementById(txtid).value;
}
}

This will add the values in all the text boxes even if not entered and gives u the total.

  Re: totaling textboxes  blkskull at 13:32 on Friday, December 15, 2006
 

Thanks for your reply.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  c++ beginner need some help
•  Menu.Prototype.cssFile
•  Perl`s Greedy and Non-Greedy Quantifiers
•  Perl`s Regular Expression Engine
•  Perl`s Regular Expression Engine
•  mysql issue with delete
•  Re: dynamic crystal report generation
•  Re: Why cannot delete file
•  Re: Set up file Down Load


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007