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

Assign a formula if a box is checked

Explorer ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

Hello, I am trying to assign a formula. If a box is checked, I'll do the following: Anyone may help, please.

 

var a = Number(this.getField("OT 1st").valueAsString);
var b = Number(this.getField("Rate x Hour 1st").valueAsString);
if(b){
if (cb != "Off")
event.value ="";
else if (cb == "Off")
event.value =(a*1.50);}

TOPICS
PDF forms

Views

87

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

correct answers 1 Correct answer

Community Expert , May 08, 2024 May 08, 2024

From the quick glance at your script I can see couple of issues:

1. You defined three variables (a, b, c), but b is not used in the calculations.
2. You used two conditions (a<=0 and a>=0), which are exhaustive and include all possibilities, so the second condition (else if (a>=0)) is effectively redundant.
You can simplify this by using if...else.
3. There is a typographical error in event.value =””; where the quotation marks are not the standard ones used they should be "".

 

 

Votes

Translate

Translate
Community Expert ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

You forgot to declare 'cb' variable.

And what is the point of 'b' variable, you only use it for condition?.

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
Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

hank you for your solution. However, it is still not working for me. I tried simplifying it using this method, but it didn't work either. Could you please help me when you have a moment?

 

var a = Number(this.getField("HrsOT1stPeriod").value);

var b = Number(this.getField("OTfirst period").value);

var c = Number(this.getField("Rate x Hour 1st").value);

if (a<=0)

event.value =””;

else if (a>=0)

event.value =((c*1.50)*a)

 

What I'm looking for is if there is overtime to show the regular time times 1.5 and multiplied by the hours 

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 Expert ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

LATEST

From the quick glance at your script I can see couple of issues:

1. You defined three variables (a, b, c), but b is not used in the calculations.
2. You used two conditions (a<=0 and a>=0), which are exhaustive and include all possibilities, so the second condition (else if (a>=0)) is effectively redundant.
You can simplify this by using if...else.
3. There is a typographical error in event.value =””; where the quotation marks are not the standard ones used they should be "".

 

 

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
Explorer ,
May 08, 2024 May 08, 2024

Copy link to clipboard

Copied

Thank you for your solution. However, it is still not working for me. I tried simplifying it using this method, but it didn't work either. Could you please help me when you have a moment?

 

var a = Number(this.getField("HrsOT1stPeriod").value);

var b = Number(this.getField("OTfirst period").value);

var c = Number(this.getField("Rate x Hour 1st").value);

if (a<=0)

event.value =””;

else if (a>=0)

event.value =((c*1.50)*a)

 

What I'm looking for is if there is overtime to show the regular time times 1.5 and multiplied by the hours 

 

 

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