Skip to main content
Participating Frequently
October 13, 2016
Question

Total from a checkbox

  • October 13, 2016
  • 1 reply
  • 279 views

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

This topic has been closed for replies.

1 reply

Inspiring
October 14, 2016

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;

}

Participating Frequently
October 14, 2016

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