Skip to Content
avatar image
Former Member

Reg : Additon of two fields in Javascript.

hi,

I have three fileds on the form by name ;

MONDAY_01.

MONDAY_02.

MONDAY_03.

I have another field by name TOTAL.

When the user enters a value in MONDAY_01 field ..

The field TOTAL should be updated.

and

When the user enters a value in MONDAY_02 field ..

The field TOTAL should be updated by adding MONDAY_01 and MONDAY_02 .

and

When the user enters a value in MONDAY_03 field ..

The field TOTAL should be updated by adding MONDAY_01 and MONDAY_02 and MONDAY_03.

Can you please tell me how to do this in JAVA SCRIPT??

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 06, 2008 at 07:56 AM

    Arjun,

    That should be pretty starightforward. In calculate event of the TOTAL field keep the language as FormCalc and write the following code:-

    Sum(MONDAY_01.rawValue,MONDAY_02.rawValue,MONDAY_03.rawValue)

    PS: I am assuming all 3 fields are decimal fields.

    Chintan

    Add comment
    10|10000 characters needed characters exceeded

    • Arjun,

      In calculate event of TOTAL field write following code in JavaScript:-

      var val1 = 0;
      var val2 = 0;
      var val3 = 0;
      
      if(MONDAY_01.rawValue != null)
      {
      	val1 = parseInt(MONDAY_01.rawValue);
      }
      if(MONDAY_02.rawValue != null)
      {
      	val2 = parseInt(MONDAY_02.rawValue);
      }
      if(MONDAY_03.rawValue != null)
      {
      	val3 = parseInt(MONDAY_03.rawValue);
      }
      var total = val1 + val2 + val3;
      
      if(total > 24) 
      {
      	xfa.host.messageBox("Please enter a value less than 24");
      	this.rawValue = "";
      }
      else
      {
      	this.rawValue = total;
      }

      Chintan