Question on adding a long list of numbers? 
Author Message
 Question on adding a long list of numbers?

Hi all,

I have following JavaScript function run in my page, as you can see this
works fine with just few SubTotals, but my SubTotals gets very large, about
400+, and this get quite slow, my question is, any way to make this faster?
may be is because of the Total = Total + SubTotals?

function showTotal()
{
var Total = 0;

var SubTotal1;
SubTotal1 = parseFloat(document.my_form.amount1.value);
if ((isNaN(SubTotal1) == false)&&(SubTotal1 != 0))
{
 Total = Total + SubTotal1;

Quote:
}

var SubTotal2;
SubTotal2 = parseFloat(document.my_form.amount2.value);
if ((isNaN(SubTotal2) == false)&&(SubTotal2 != 0))
{
 Total = Total + SubTotal2;

Quote:
}

....

document.AR_invoice_update.total_paid.value = Total;
setTimeout("showTotal()",300);

Quote:
}

Thanks for help

Raymond Yap



Mon, 05 Apr 2004 04:24:40 GMT  
 Question on adding a long list of numbers?
Raymond,

Do you have really 400+ entry fields on your form, and a couple of script
lines for each block?

The script would be more manageable if you use a loop to iterate through
all fields. It would shorten the script considerably, as well as reduce the
number of variables used.

Some small tips, that might or might not accelerate:
- use " ! isNaN(subtotal) "  instead of " isNaN(subtotal) == false "
- why the check "subtotal != 0" ? If it IS 0, then the total won't be
affected!
- try " Total += SubTotal " instead of " Total = Total + SubTotal "
- are you really calling showTotal again at the end of the function?
   If you want to show the current total as the fields are filled in,
   try using the "onChange" event to only add changed values one at a time
   to the total, maybe together with "onFocus" to remember the old value
  (so you can subtract that from the total)

Hans Kesting


Quote:
> Hi all,

> I have following JavaScript function run in my page, as you can see this
> works fine with just few SubTotals, but my SubTotals gets very large,
about
> 400+, and this get quite slow, my question is, any way to make this
faster?
> may be is because of the Total = Total + SubTotals?

> function showTotal()
> {
> var Total = 0;

> var SubTotal1;
> SubTotal1 = parseFloat(document.my_form.amount1.value);
> if ((isNaN(SubTotal1) == false)&&(SubTotal1 != 0))
> {
>  Total = Total + SubTotal1;
> }

> var SubTotal2;
> SubTotal2 = parseFloat(document.my_form.amount2.value);
> if ((isNaN(SubTotal2) == false)&&(SubTotal2 != 0))
> {
>  Total = Total + SubTotal2;
> }

> ....

> document.AR_invoice_update.total_paid.value = Total;
> setTimeout("showTotal()",300);
> }

> Thanks for help

> Raymond Yap



Mon, 05 Apr 2004 20:52:04 GMT  
 Question on adding a long list of numbers?
Hi Hans,

Thank you for all this wonderful suggestions.

Regards

Raymond Yap


Quote:
> Raymond,

> Do you have really 400+ entry fields on your form, and a couple of script
> lines for each block?

> The script would be more manageable if you use a loop to iterate through
> all fields. It would shorten the script considerably, as well as reduce
the
> number of variables used.

> Some small tips, that might or might not accelerate:
> - use " ! isNaN(subtotal) "  instead of " isNaN(subtotal) == false "
> - why the check "subtotal != 0" ? If it IS 0, then the total won't be
> affected!
> - try " Total += SubTotal " instead of " Total = Total + SubTotal "
> - are you really calling showTotal again at the end of the function?
>    If you want to show the current total as the fields are filled in,
>    try using the "onChange" event to only add changed values one at a time
>    to the total, maybe together with "onFocus" to remember the old value
>   (so you can subtract that from the total)

> Hans Kesting



> > Hi all,

> > I have following JavaScript function run in my page, as you can see this
> > works fine with just few SubTotals, but my SubTotals gets very large,
> about
> > 400+, and this get quite slow, my question is, any way to make this
> faster?
> > may be is because of the Total = Total + SubTotals?

> > function showTotal()
> > {
> > var Total = 0;

> > var SubTotal1;
> > SubTotal1 = parseFloat(document.my_form.amount1.value);
> > if ((isNaN(SubTotal1) == false)&&(SubTotal1 != 0))
> > {
> >  Total = Total + SubTotal1;
> > }

> > var SubTotal2;
> > SubTotal2 = parseFloat(document.my_form.amount2.value);
> > if ((isNaN(SubTotal2) == false)&&(SubTotal2 != 0))
> > {
> >  Total = Total + SubTotal2;
> > }

> > ....

> > document.AR_invoice_update.total_paid.value = Total;
> > setTimeout("showTotal()",300);
> > }

> > Thanks for help

> > Raymond Yap



Mon, 05 Apr 2004 21:52:02 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Adding number to each item found in a list

2. Adding an entry to the Add Remove Programs list

3. Converting string to a number (long)

4. Unable to execute - arguments list is too long

5. argument list too long errors

6. Unable to execute - arguments list is too long

7. unable to execute - arguments list is too long...

8. ADSI add user to goup take long time

9. Build Numbers List?

10. problem in adding numbers using java script

11. adding sequentia; page numbers in postscript files

12. add page number

 

 
Powered by phpBB® Forum Software