Skip to main content
Alizai
Participating Frequently
August 10, 2023
Answered

Help in finding right script

  • August 10, 2023
  • 2 replies
  • 976 views

I got a script from chatGPT for adobe acrobat dc pro

 

"When I select a value from dropdown list and want on a textbox automatically like

When I select N/A then textbox should be empty

when I select 0 then textbox should have a value of 0%

when I select 1 then textbox should have a value of 25%

when I select 2 then textbox should have a value of 50%

when I select 3 then textbox should have a value of 75%

when I select 4 then textbox should have a value of 100%"

 

but I dont get any result when I run the followng javascript, 

 

// Replace "DropdownFieldName" and "TextboxFieldName" with the actual field names in your document
var dropdownField = "DropdownFieldName";
var textboxField = "TextboxFieldName";

// Define the mapping of dropdown values to textbox values
var valueMapping = {
"N/A": "",
"0": "0%",
"1": "25%",
"2": "50%",
"3": "75%",
"4": "100%"
};

// Get the dropdown and textbox fields
var dropdown = this.getField(dropdownField);
var textbox = this.getField(textboxField);

// Set up a change event handler for the dropdown field
dropdown.setAction("OnBlur", function() {
var selectedValue = dropdown.value;

// Set the textbox value based on the selected value from the dropdown
if (valueMapping.hasOwnProperty(selectedValue)) {
textbox.value = valueMapping[selectedValue];
}
});

This topic has been closed for replies.
Correct answer Nesa Nurani

If you format the text field as percentage, then set the export value like this:

In export value for 0 enter 0 for 1 give it export value 0.25...etc

 

If you didn't set format in text field, then set export values like this:

In export value for 0 enter 0% for 1 give it export value 25%...etc

 

2 replies

Nesa Nurani
Community Expert
Community Expert
August 11, 2023

Add percentage as 'export value' to dropdown choices, then use this as custom calculation script of dropdown field:

this.getField("textboxField").value = event.value;
Alizai
AlizaiAuthor
Participating Frequently
August 11, 2023

It works but not according to what I want, it gives what is inside dropdown list, i.e if "0" then it gives 0%, if "1" then gives 1% and so on, I need if dropdown value is "0", textbox value should be 0% and if dropdown value is "1", textbox value should be "25%" and so on. so please make such script or coding to give the required result. Thanks

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
August 11, 2023

If you format the text field as percentage, then set the export value like this:

In export value for 0 enter 0 for 1 give it export value 0.25...etc

 

If you didn't set format in text field, then set export values like this:

In export value for 0 enter 0% for 1 give it export value 25%...etc

 

S_S
Community Manager
Community Manager
August 10, 2023

Hi @Alizai,

 

Hope you are doing well. Thank you for writing in!

 

Instead, I prefer the If-Else statement to capture the values for drop-downs and fields. 

I tried a script that worked for me:

function onDropdownChange(event) {
  var dropdown = event.target;
  var textbox = document.getElementById("textbox");

  if (dropdown.value == "N/A") {
    textbox.value = "";
  } else if (dropdown.value == "0") {
    textbox.value = "0%";
  } else if (dropdown.value == "1") {
    textbox.value = "25%";
  } else if (dropdown.value == "2") {
    textbox.value = "50%";
  } else if (dropdown.value == "3") {
    textbox.value = "75%";
  } else if (dropdown.value == "4") {
    textbox.value = "100%";
  }
}

document.addEventListener("change", onDropdownChange);

 

Hope this helps.

 

Note: I am not an expert when it comes to scripting, but this is something that worked for me.

 

-Souvik

Bernd Alheit
Community Expert
Community Expert
August 11, 2023

The script is for web browsers, not Adobe Acrobat..

Alizai
AlizaiAuthor
Participating Frequently
August 11, 2023

Ok then please make a script for adobe acrobat pro, I would be grateful.