Only Spawn One Page Determined by Dropdown Selection
I'm not a coder and am struggling. I need the PDF form to spawn a page from templates based on the option selected in the dropdown. If the user changes their selection, I need the spawned page removed and replaced with a page spawned from the tempalte associated with the new selection.
I have a dropdown field and each option corresponds to a template. The script I have isn't working (nothing happens).
Also, is there any way to set the tab order to resume from the dropdown and not move to the spawned page?
Any help would be greatly appreciated!!!
Here's the code I have in "2 Type" Dropdown properties under Actions/OnBlur/Run a Javascript:
var dropdownField = "2 Type";
var pageTemplates = {
"Joint": "Template_Joint",
"Trust": "Template_Trust",
"Estate": "Template_Estate",
"C Corp": "Template_Business",
"S Corp": "Template_Business",
"LLC": "Template_Business",
"Sole Proprietorship": "Template_Business",
"Partnership": "Template_Business",
"Traditional": "Template_Traditional",
"Roth": "Template_Traditional",
"Simple IRA": "Template_Simple",
"Self-Employed 401(k)": "Template_SelfEmployed401k",
"Pooled 401(k)/PSP": "Template_Pooled401k",
"UTMA": "Template_UTMA",
"Annuity": "Template_Annuity"
};
this.getField(dropdownField).setAction("OnBlur", function() {
spawnAssociatedPage();
});
function spawnAssociatedPage() {
var selectedValue = this.getField(dropdownField).value;
var templateName = pageTemplates[selectedValue];
// Remove previously spawned pages
removeSpawnedPages();
if (templateName) {
this.spawnPageFromTemplate(templateName);
}
}
function removeSpawnedPages() {
for (var i = 0; i < this.numFields; i++) {
var fieldName = this.getNthFieldName(i);
if (fieldName.startsWith("Template_")) {
this.removeField(fieldName);
}
}
}
