[EMAIL PROTECTED] (SUPRIYA MISRA) wrote:

> Now I have another problem.
> In JavaScirpt I have;
> 
> var total=0.0;
> var x;
> 
> for loop
> x=document.currentForm.elements["actHour["+loop+"].faHrsDay1"].value;
> alert(x);
> total=total+x;
> alert(total);
> end loop
> 
> x gets the correct values like 1,2,3
> but total=0.0 then 0.01, then 0.012 and so on.
> 
> It is doing string concatenation instead of adding them.


That is because x is a string and if either of the arguments of + is a string
it will do concatenation. You need to force x to be a number using one of:

total = total + Number(x);

or

total = total + (x - 0);


Duncan Harris
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hartford, Cheshire, U.K., Tel: 07968 060418
Looking for STRUTS contract work in the U.K.

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to