Copy link to clipboard
Copied
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];
}
});
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Copy link to clipboard
Copied
@Alizai, You get the error because document is not defined as a variable in the above context.
Try adding this to the above code as the first line:
var document = window.document;
Hope this helps.
-Souvik
Copy link to clipboard
Copied
The script is for web browsers, not Adobe Acrobat..
Copy link to clipboard
Copied
Ok then please make a script for adobe acrobat pro, I would be grateful.
Copy link to clipboard
Copied
@AlizaiYou don't need a complex script, take a look at Nesa's post.
Copy link to clipboard
Copied
Add percentage as 'export value' to dropdown choices, then use this as custom calculation script of dropdown field:
this.getField("textboxField").value = event.value;
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more