Copy link to clipboard
Copied
I am attempting to create a form that has 5 variable selection fields show in referenced spots within a paragraph.
There a 4 paragraphs to choose from in the very first dropdown question.
This is what I have written, but am confused by which fields need custom calculations.
Dropdown3 is the first paragraph driver and the other 5 variable input fields are below.
const frequency = this.getField('Dropdown8').value
const date = this.getField('Date7_af_date').value
const target = this.getField('Text9').value
const calcmonths = this.getField('Text99').value
const periodend = this.getField('Dropdown88').value
// Function to update Text5 based on Dropdown3 selection
function updateText5 () {
const dropdown3Value = this.getField('Dropdown3').value
const text5Field = this.getField('Text5')
if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit') {
text5Field.value = 'This is test paragraph 1 ' + target + and ' + frequency + ' and ' + calcmonths + ' and ' + date + " and " + calcmonths + ' end paragraph.'
} else if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash') {
text5Field.value = 'This is a test of paragraph 2 ' + frequency + ' and ' + date + ' and ' + target + '.'
} else if (dropdown3Value === 'Consolidate Minimum Current Ratio C&I, CRE') {
text5Field.value = 'This a test paragrapgh 3 ' + target + ' and ' + periodend + ' and ' + date + '.'
} else if (dropdown3Value === 'Consolidate Maximum Debt/TNW C&I, CRE') {
text5Field.value = 'This is a test paragraph 4' + target + 'and ' + periodend + ' and ' + calcmonths + " end."
}
}
// Set the custom calculation script for Dropdown3 to update Text5
this.getField("Dropdown3").setAction("Validate", "updateText5();");
// Initial call to set the value of Text5 based on the current selection of Dropdown3
updateText5();
Thank you!
Copy link to clipboard
Copied
Use this as custom calculation script of "Text5" field:
var frequency = this.getField("Dropdown8").valueAsString;
var date = this.getField("Date7_af_date").valueAsString;
var target = this.getField("Text9").valueAsString;
var calcmonths = this.getField("Text99").valueAsString;
var periodend = this.getField("Dropdown88").valueAsString;
var dropdown3Value = this.getField("Dropdown3").valueAsString;
if (dropdown3Value === "Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit") {
event.value = "This is test paragraph 1 " + target + " and " + frequency + " and " + calcmonths + " and " + date + " and " + calcmonths + " end paragraph.";}
else if (dropdown3Value === "Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash") {
event.value = "This is a test of paragraph 2 " + frequency + " and " + date + " and " + target + ".";}
else if (dropdown3Value === "Consolidate Minimum Current Ratio C&I, CRE") {
event.value = "This a test paragraph 3 " + target + " and " + periodend + " and " + date + ".";}
else if (dropdown3Value === "Consolidate Maximum Debt/TNW C&I, CRE") {
event.value = "This is a test paragraph 4 " + target + " and " + periodend + " and " + calcmonths + " end.";}
else
event.value = "";
Copy link to clipboard
Copied
- Use var instead of const.
- The setAction line should only be used once, from the Console. Do not include it in your code.
Also, it says that it's setting a calculation script, when in fact it's a validation one.
- The last line (the call to the updateText5 function) should be removed entirely.
Copy link to clipboard
Copied
Also, move all of the variable definitions into the function.
Copy link to clipboard
Copied
Thank you for this,
I am a little confused by what you refer to when you say Console?
I updated the cont to var.
Really apprecaite your help!
Copy link to clipboard
Copied
The JS Console is where you execute code without it being a part of a file.
See: https://acrobatusers.com/tutorials/javascript_console
Copy link to clipboard
Copied
Copy link to clipboard
Copied
This is correct.
Look at the properties of the dropdown.
Copy link to clipboard
Copied
I appreciate your help.
Attached is a snip of the Text5 proprties.
{
var dropdown3Value = this.getField('Dropdown3').value
var text5Field = this.getField('Text5')
var frequency = this.getField('Dropdown8').value
var date = this.getField('Date7_af_date').value
var target = this.getField('Text9').value
var calcmonths = this.getField('Text99').value
var periodend = this.getField('Dropdown88').value
if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit') {
text5Field.value = 'This is test paragraph 1 ' + target + ' and ' + frequency + ' and ' + calcmonths + ' and ' + date + " and " + calcmonths + ' end paragraph.'
} else if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash') {
text5Field.value = 'This is a test of paragraph 2 ' + frequency + ' and ' + date + ' and ' + target + '.'
} else if (dropdown3Value === 'Consolidate Minimum Current Ratio C&I, CRE') {
text5Field.value = 'This a test paragrapgh 3 ' + target + ' and ' + periodend + ' and ' + date + '.'
} else if (dropdown3Value === 'Consolidate Maximum Debt/TNW C&I, CRE') {
text5Field.value = 'This is a test paragraph 4' + target + 'and ' + periodend + ' and ' + calcmonths + " end."
}
}
Copy link to clipboard
Copied
Use this as custom calculation script of "Text5" field:
var frequency = this.getField("Dropdown8").valueAsString;
var date = this.getField("Date7_af_date").valueAsString;
var target = this.getField("Text9").valueAsString;
var calcmonths = this.getField("Text99").valueAsString;
var periodend = this.getField("Dropdown88").valueAsString;
var dropdown3Value = this.getField("Dropdown3").valueAsString;
if (dropdown3Value === "Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit") {
event.value = "This is test paragraph 1 " + target + " and " + frequency + " and " + calcmonths + " and " + date + " and " + calcmonths + " end paragraph.";}
else if (dropdown3Value === "Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash") {
event.value = "This is a test of paragraph 2 " + frequency + " and " + date + " and " + target + ".";}
else if (dropdown3Value === "Consolidate Minimum Current Ratio C&I, CRE") {
event.value = "This a test paragraph 3 " + target + " and " + periodend + " and " + date + ".";}
else if (dropdown3Value === "Consolidate Maximum Debt/TNW C&I, CRE") {
event.value = "This is a test paragraph 4 " + target + " and " + periodend + " and " + calcmonths + " end.";}
else
event.value = "";
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Did you place script in "Text5" field under 'Custom calculation script' ?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You're not using the code provided by Nesa. You need to use event.value to assign the new value, not text5Field.value .
Copy link to clipboard
Copied
Thanks for the response, I copied her code as above and put it in the custom calculation box?
Can you explain what you are refering to?
Copy link to clipboard
Copied
I think I did...
Copy link to clipboard
Copied
I copied Nesa's code and pasted into the custom calc box in text5 properties.
Am I not understanding something?
Copy link to clipboard
Copied
In your last post the code you posted was different. If you copied it directly, without editing it, then it should work.
If it doesn't, check the JS Console (Ctrl+J) for error messages.