Skip to main content
Nsmjc
Participant
May 8, 2016
Question

Multiple if statements

  • May 8, 2016
  • 2 replies
  • 543 views

I am using this javascrpit which works well

if (this.getField("CheckBox2").isBoxChecked(0)=="1")

{event.value=this.getField("ofTrainingDays").value*10.00;} else event.value = 0;

if (event.value==0)

  1. event.value="";

I need to add a statement to the start of it to check the status of check box 3.   So if checkbox 3 is checked then the rest of the formula will be ignored and the "ofTrainingDays" will have a value of 0.

if (this.getField("CheckBox3").isBoxChecked(0)=="1")

{event.value=this.getField("ofTrainingDays").value0;} else

if (this.getField("CheckBox2").isBoxChecked(0)=="1")

{event.value=this.getField("ofTrainingDays").value*10.00;} else event.value = 0;

if (event.value==0)

  1. event.value="";

However this does not work correctly any Ideas

This topic has been closed for replies.

2 replies

Inspiring
May 8, 2016

Since the field will either have the calculated value or a null string as a result, one can default the field value to a null string and then only set the field's value if the boxed is checked. I prefer to use the value of the check box in case the form is changed to have 2 check boxes for this item. An unslelected check box will have a value of "Off" so any value not equal to "Off" means the box has been checked.

event.value = "";

if (this.getField("CheckBox3").value  != "Off")  {

    event.value = this.getField("ofTrainingDays").value;

    }

JR Boulay
Community Expert
Community Expert
May 8, 2016

Hi.

In this case there is no need to get the value of a checkbox, it's checked or not.

Try this :

if (this.getField("CheckBox3").isBoxChecked(0)) {

    event.value = this.getField("ofTrainingDays").value;

    }

else if (this.getField("CheckBox2").isBoxChecked(0)) {

    event.value = this.getField("ofTrainingDays").value * 10;

    }

else {

     event.value = "";

     }

Acrobate du PDF, InDesigner et Photoshopographe