cancel
Showing results for 
Search instead for 
Did you mean: 

Reg : Additon of two fields in Javascript.

Former Member
0 Kudos

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??

Accepted Solutions (1)

Accepted Solutions (1)

chintan_virani
Active Contributor
0 Kudos

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

Former Member
0 Kudos

HI ,

Chintan ,

I need in Javascript ..not in Form Calc .

chintan_virani
Active Contributor
0 Kudos

Arjun,

Any special reason of doing in JavaScript? The reason I would prefer FormCalc here is because Sum is available as pre-defined function and if you use JavaScript you will have to do some checks, parse the enterred values etc and then total it.

Chintan

Former Member
0 Kudos

HI Chitan,

Yes..I need in Java script only.

The reason is : I need TOTAL value by adding

MONDAY_01

MONDAY_02

MONDAY_03 .

When the value of field TOTAL excceds 24...I need to raise an error message.

So to raise an error message Iam using Javascript

if (TOTAL.rawValue > 24)

{

xfa.host.messageBox("Please enter a value less than 24");

}.

For adding ...Iam using Form calc

SUM(MONDAY_01 ,MONDAY_02 ,MONDAY_03 )

.

So here the problem is , I cannot use FORM CALC for adding and JAVASCRIPT for raising error message .

So Either I need both addition and raising error message in JAVASCRIPT or FORM CALC..

Can you please help

chintan_virani
Active Contributor
0 Kudos

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

Answers (0)