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

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

Contributor ,
Jun 01, 2023 Jun 01, 2023

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;

TOPICS
JavaScript
551
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 ,
Jun 01, 2023 Jun 01, 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;
	}
}

 

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
Contributor ,
Jun 01, 2023 Jun 01, 2023

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

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 ,
Jun 01, 2023 Jun 01, 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;
	}
}

 

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
Contributor ,
Jun 02, 2023 Jun 02, 2023

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

 

  

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
Contributor ,
Jun 02, 2023 Jun 02, 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;

}

 

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 ,
Jun 02, 2023 Jun 02, 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);

}

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
Contributor ,
Jun 02, 2023 Jun 02, 2023
LATEST

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

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