• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Javascript help

Community Beginner ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

Field name: box1, box2, box3, box4, box5

All of the above are check boxes,

Box6 is a total from another field

Now i need a conditional script for box7 if box1 and box2 is checked

Substract 20 from box6 and if box3 and box4 is checked substract 45 from box6

and if box5 is checked substract 10 from box6 or else leave blank      

Thanks!!!!

TOPICS
JavaScript

Views

210

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

You do this with a custom calculation script for "box7" that checks the state of the checkboxes:

 

var b1 = this.getField("box1").value != "Off";
var b2 = this.getField("box2").value != "Off";
var b3 = this.getField("box3").value != "Off";
var b4 = this.getField("box4").value != "Off";
var b5 = this.getField("box5").value != "Off";

var v = this.getField("box6").value;

if (b1 && b2) {
    event.value = v - 20;
}
else if (b3 && b4) {
    event.value = v - 45;
}
else if (b5) {
    event.value = v - 10;
}
else {
    event.value = "";
}

 This does not take into account the case where e.g. all five boxes are chexed. I will leave that up to you to implment that and any error checking (e.g. what happens if there is no numeric value in box6). 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 29, 2021 Apr 29, 2021

Copy link to clipboard

Copied

LATEST

It works thanks!!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines