Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Javascript / Client Side Development

addition


I have following function, but how can I  do addition ?
if
 f.Field1.value =2
 f.Field3.value =3
 f.Field4.value =1

then
 f.Total.value =231, instead of 6

function update( ) {
var f = document.myform
f.Total.value = f.Field1.value + f.Field2.value + f.Field3.value
return true;

}

Many thanks.
Sorry, I mean I want it 6, instead of 231

On Mar 14, 1:38 pm, "magix" <m@asia.com> wrote:

> I have following function, but how can I  do addition ?
> function update( ) {
> var f = document.myform
> f.Total.value = f.Field1.value + f.Field2.value + f.Field3.value
> return true;
> }

function update( ) {
var f = document.forms['myform'] //- this part is not important
f.Total.value = +f.Field1.value + +f.Field2.value + +f.Field3.value
return true;

"magix" <m@asia.com> wrote:
>I have following function, but how can I  do addition ?
>if
> f.Field1.value =2
> f.Field3.value =3
> f.Field4.value =1

parseInt(f.Field1.value) + parseInt(f.Field3.value) +
parseInt(f.Field4.value)

--
Tim Slattery
Slatter@bls.gov
http://members.cox.net/slatteryt

On Mar 15, 5:38 am, "magix" <m@asia.com> wrote:

> I have following function, but how can I  do addition ?
> if
>  f.Field1.value =2
>  f.Field3.value =3
>  f.Field4.value =1

> then
>  f.Total.value =231, instead of 6

> function update( ) {
> var f = document.myform
> f.Total.value = f.Field1.value + f.Field2.value + f.Field3.value
> return true;

> }

The values returned by form controls are strings, they must be
converted to numbers or the '+' operator will cause concatenation, not
addition:

<URL: http://www.jibbering.com/faq/#FAQ4_21 >

--
Rob

magix wrote:
> I have following function, but how can I  do addition ?
> f.Total.value =231, instead of 6

http://www.javascripttoolbox.com/bestpractices/#plus

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com

Tim Slattery said the following on 3/14/2007 4:11 PM:

> "magix" <m@asia.com> wrote:

>> I have following function, but how can I  do addition ?
>> if
>> f.Field1.value =2
>> f.Field3.value =3
>> f.Field4.value =1

> parseInt(f.Field1.value) + parseInt(f.Field3.value) +
> parseInt(f.Field4.value)

And if Field1.value = "09" ?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc