Skip to main content
Participant
January 6, 2017
Question

Javascript Calculation Dependent on which Checkbox is Checked

  • January 6, 2017
  • 1 reply
  • 298 views

I am trying to create javascript to populate a field (FieldText13) with a dollar amount based upon whether or not CheckBox9 (2 hours) or CheckBox11 (4 hours) is checked multiplied by the dollar amount that is entered by the user in FieldText11.

I've made multiple attempts but cannot get the javascript to work. 

Thank you.

var cb1 = this.getField("CheckBox9").isBoxChecked(0);
var cb2 = this.getField("CheckBox11").isBoxChecked(0);

if (cb1 && cb2) {
    event.value = "";
}
else if (cb1) {
    event.value = ("FillText09" * "FillText09val");
}
else if (cb2) {
    event.value = ("FillText11" * "FillText11val");
}
else {
    event.value = "";

}

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
January 6, 2017

First of all, if those check-boxes are mutually exclusive then you should set them up like that. You can do so by giving them the same name but different export values.

Regarding your script: To access the value of a field you must use the getField method and then the value property, not just write out the field's name. So instead of this:

event.value = ("FillText09" * "FillText09val");

Use this:

event.value = this.getField("FillText09").value * this.getField("FillText09val").value;