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

Assign a formula if a box is checked

Explorer ,
May 06, 2024 May 06, 2024

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
419
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
May 08, 2024 May 08, 2024
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 "".

 

 

View solution in original post

Translate
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 06, 2024 May 06, 2024

You forgot to declare 'cb' variable.

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

Translate
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

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 

Translate
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
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 "".

 

 

Translate
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

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 

 

 

Translate
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