Admissions up front, I don't know coding. This has been piece-mealed from my own reasearch with a bit of assistance from ChatGPT. I have a form with two dropdown fields; "News Outlet" and "Author". I want the "Author" drop-down to only populate with a select list of authors based on the chosen News Outlet. This is the code that I have written in the News Outlet validate tab: var newsOutletField = this.getField("News Outlet"); var authorField = this.getField("Author"); // Define a mapping of News Outlets to their corresponding authors var authorsByOutlet = { "World News Today": ["Luarie Lee", "Pete Downer", "Jake Fuller"], "Global News Network": ["Barbara Marcus", "William Donovan", "Duke Cannon"], "Associated Press": ["Steve Plank", "Susie Grove", "Murray Slaughter"], "News Online": ["Martin Hall", "Brandy Cook", "Mary Richards"], "Europe News Now": ["Mike Anderson", "Adam Carrington", "Rita Hanson"], "Reuters": ["Robyn Cross", "Pam Turner", "Jake Frampton"] }; // Function to update the authors based on the selected News Outlet function updateAuthors() { var selectedOutlet = newsOutletField.valueAsString; authorField.clearItems(); var authors = authorsByOutlet[selectedOutlet]; if (authors) { authorField.setItems(authors); } } // Add a "Validate" action to the "News Outlet" dropdown field newsOutletField.setAction("Validate", "updateAuthors();"); // Initially, populate the authors based on the default selection updateAuthors(); When it runs, (preview form) for some reason it erases all of the code and the only thing left in the script box is: updateAuthors(); During that first preview run, the Author drop-down populates with a select list of authors, and the list updates, but they're the wrong associations. If I exit preview and then preview form again, the list remains with the last selection of authors and doesn't update anymore. I'm not sure what's happening or why it's clearing all of the code. The Debug console hasn't been any help either, but that could just be my ignorance. However it doesn't report any errors in the console. Any help and/or insights would be appreciated. Document in question attached.
... View more