2 Replies Latest reply on Oct 14, 2016 8:53 AM by jasonz82977625

# Total from a checkbox

lest say for this the Bonus = 1 and Modifier = 2

with no box checked i should get 1

if i check Pro i get 1 should be 3

if i check EXP i get 4

// JavaScript Document

var x = this.getField("BONUS").value;

var y = this.getField("Modifier").value;

if (this.getField("PRO").value === "Yes") {

this.getField("Total").value === x+y; }

else

this.getField("Total").value = y;

if  (this.getField("EXP").value === "Yes") {

this.getField("Total").value = x+x+y; }

else (

this.getField("T

• ###### 1. Re: Total from a checkbox

Are you aware that JavaScript has different operators for testing for equality and setting a value?

There are 2 equality operators, "==" and "===". The first is for a match the second is for an exact match.

Values are set by using the "=" operator.

// JavaScript Document

var x = this.getField("BONUS").value;

var y = this.getField("Modifier").value;

if (this.getField("PRO").value == "Yes")  // Pro has been selected;

{

this.getField("Total").value = x + y;  // add values for bonus and modifier;

}

else

{

this.getField("Total").value = y; // only modifier;

}

• ###### 2. Re: Total from a checkbox

Thanks good to know added to my notes, self learning JavaScript

so it should look like this

// JavaScript Document

var x = this.getField("BONUS").value;

var y = this.getField("Modifier").value; //

if (this.getField("PRO").value == "Yes") // check to see if field = yes

{

this.getField("Total").value = x+y; //should add Var x+x but does not

}

else

{

this.getField("Total").value = y; // if Pro Field does not match Total field will = Y

if (this.getField("EXP").value == "Yes") // check to see if field = yes

{

this.getField("Total").value = x+x+y; // adds X+X+Y

}

else

{

this.getField("Total").value = y; // if EXP Field does not match Total field will = Y

When test the each if statement independently they work as soon as i add the second if statement it seem to bypass the first one