Skip to main content
Inspiring
June 1, 2023
Answered

Calculation script with RB as trigger, dropdown export value multiplied by textfield value

  • June 1, 2023
  • 3 replies
  • 745 views

Not sure if this is possible in Acrobat- I have the following calculation in an online website plugin and I want to include it in my acrobat form. Possible? Thanks in advance Community!!

*NOTE "TextField1.value" is the numerical value entered by the user into the TextField1 and "Dropdown1.export value" is the export value (decimal value) of the Dropdown1 field selection.

 

if( {TextField1.value} < 5000.01 😞
({TextField1.value}*(0.05+({Dropdown1.export value)))
elseif({TextField1.value}> 5000):
((({TextField1.value}-5000)*0.05))+((5000*(0.05+({Dropdown1.export value}))))
else:
0
endif;

This topic has been closed for replies.
Correct answer try67

Quite a lot of unnecessary parentheses and curly brackets there... I think this is what you meant:

 

if (this.getField("RBField1").valueAsString=="Yes") {
	var TextField1 = Number(this.getField("TextField1").valueAsString);
	var Dropdown1 = Number(this.getField("Dropdown1").valueAsString);

	if (TextField1 < 5000.01) {
		event.value = TextField1 * (0.05 + Dropdown1);
	} else if (TextField1 > 5000) {
		event.value = (((TextField1 - 5000) * 0.05)) + (5000 * (0.05 + Dropdown1));
	} else {
		event.value = 0;
	}
}

 

3 replies

Inspiring
June 2, 2023

Thank you Nesa for your valuable assistance and time!! I'm still having problems with a post you answered earlier. Here's what I have adapted from your custom calculation script using the ternery operator. Your guidance was correct, but my explanation in my 1st post excluded that I had existing calculation scripts to show/hide other text fields based on the dropdown selection. I've attempted unsuccessively to tweak your statements into single arguments, but have been yet unsuccessful. Below is my latest attempt. Any guidance greatly appreciated! Thanks again Nesa for all you do!!

 

var vehicleType = (this.getField("VehicleTypDD").value);

if (vehicleType == "CAR-TRUCK-SUV-VAN-BUS-RVs") {

this.getField("Weight82040").display = display.visible;

this.getField("LengthFeet82040").display = display.hidden;

this.getField("LengthInch82040").display = display.hidden;

this.getField("EngineSize82040").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(vehicleType == "CAR-TRUCK-SUV-VAN-BUS-RVs" = true);
}

else if (vehicleType == "TOWABLE RVs") {

this.getField("Weight82040").display = display.hidden;

this.getField("LengthFeet82040").display = display.visible;

this.getField("LengthInch82040").display = display.visible;

this.getField("EngineSize82040").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(vehicleType == "TOWABLE RVs" = true);
}

else if (vehicleType == "MOTORCYCLE-AUTOCYCLE") {

this.getField("Weight82040").display = display.visible;

this.getField("LengthFeet82040").display = display.hidden;

this.getField("LengthInch82040").display = display.hidden;

this.getField("EngineSize82040").display = display.visible;

this.getField("CkBxMC84990").checkThisBox(vehicleType == "MOTORCYCLE-AUTOCYCLE" = true);
}

else if (vehicleType == "TRAILERS-SEMITRAILERS") {

this.getField("Weight82040").display = display.visible;

this.getField("LengthFeet82040").display = display.visible;

this.getField("LengthInch82040").display = display.visible;

this.getField("EngineSize82040").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(vehicleType == "TRAILERS-SEMITRAILERS" = true);

}

else {

this.getField("Weight82040").display = display.hidden;

this.getField("LengthFeet82040").display = display.hidden;

this.getField("LengthInch82040").display = display.hidden;

this.getField("EngineSize82040").display = display.hidden;

}

 

Nesa Nurani
Community Expert
Community Expert
June 2, 2023

You can use it like this in the condition for which you want to checkbox to be checked:

this.getField("CkBxMV84990").checkThisBox(0, true);

then replace true with false in 'else' condition to uncheck checkbox.

Example from part of your script:

else if (vehicleType == "TRAILERS-SEMITRAILERS") {

this.getField("Weight82040").display = display.visible;

this.getField("LengthFeet82040").display = display.visible;

this.getField("LengthInch82040").display = display.visible;

this.getField("EngineSize82040").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(0, true);

}

else {

this.getField("Weight82040").display = display.hidden;

this.getField("LengthFeet82040").display = display.hidden;

this.getField("LengthInch82040").display = display.hidden;

this.getField("EngineSize82040").display = display.hidden;

this.getField("CkBxMV84990").checkThisBox(0, false);

}

Inspiring
June 2, 2023

You're too Awesome!!! Thank you Nesa!!!!

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 1, 2023

Quite a lot of unnecessary parentheses and curly brackets there... I think this is what you meant:

 

if (this.getField("RBField1").valueAsString=="Yes") {
	var TextField1 = Number(this.getField("TextField1").valueAsString);
	var Dropdown1 = Number(this.getField("Dropdown1").valueAsString);

	if (TextField1 < 5000.01) {
		event.value = TextField1 * (0.05 + Dropdown1);
	} else if (TextField1 > 5000) {
		event.value = (((TextField1 - 5000) * 0.05)) + (5000 * (0.05 + Dropdown1));
	} else {
		event.value = 0;
	}
}

 

Inspiring
June 2, 2023

Awesome!!Thank you Try67 for your guidance ad assistance- very appreciated!!! 

 

  

Inspiring
June 1, 2023

Also, the RBField1.value is "Yes" and triggers the calcultation, or "No" and does nothing.