Copy link to clipboard
Copied
I recently used Thom Parker's "Changing another field with combo box (drop down) selection" article (Thanks Thom!) to make a form that has two text boxes and one drop down. Depending on what you select in the drop down, the two text boxes are populated with unique sentences. What I would like to do is have an additional drop down that contains a word or number selection that when chosen would place it into one of the sentences. For my form, I have a drop down that you select why you are advising someone, which populates the 'Reason for Advising' text field with a small explanation and also populates 'Plan of Action' with a short summary of what we intend to do. Right now I have created an underlined section in the sentence where the user can simply type additional information, but I would like to have a second drop down that they could choose from to populate that area of the sentence. So looking at Thom's original document script:
// Place all pre-population data into a single data structure
var DeptData = { Accounting:{ contact: "Steala Damuni", email: "accounting@mycomp.com", deptnum: "cmp1234" }, Engineering:{ contact: "Frank N. Stien", email: "engineering@mycomp.com", deptnum: "eng1234" }, Marketing :{ contact: "Shelly Oughtbuks", email: "marketing@mycomp.com", deptnum: "mkt1234" }, ITSupport:{ contact: "Goah Wei", email: "it@mycomp.com", deptnum: "its1234" }};
function SetFieldValues(cDeptName) {
// Populate fields with values from the Department Data Object
this.getField("DeptContact").value = DeptData[cDeptName].contact;
this.getField("DeptEmail").value = DeptData[cDeptName].email;
this.getField("DeptNumber").value = DeptData[cDeptName].deptnum;
}
So for example, what changes could be made so that the email domain in the above script would be filled based on the results of a second drop down? I am nowhere near an expert on this, and I have done well just to get by tweaking other peoples scripts. I assume I can create another variable, I just don't know how to place it in the middle of the sentence. Thanks for any help or suggestions.
Mike
This is getting a little complicated, so bare with me
The trick is to put a place holder in the text you want modified. It just needs to be a few characters that are never going to appear in regular text, such as "%%". Then the code that sets the field value would also replace the placeholder with the chosen option. say from a dropdown named "drop2".
So the code that sets one of the values above would change to
this.getField("DeptEmail").value = DeptData[cDeptName].email.replace(/%%/,this.getFiel
...Copy link to clipboard
Copied
This is getting a little complicated, so bare with me
The trick is to put a place holder in the text you want modified. It just needs to be a few characters that are never going to appear in regular text, such as "%%". Then the code that sets the field value would also replace the placeholder with the chosen option. say from a dropdown named "drop2".
So the code that sets one of the values above would change to
this.getField("DeptEmail").value = DeptData[cDeptName].email.replace(/%%/,this.getField("drop2"));
But this also has to be done for the "drop2" selection. So now you need another function similar to "SetFieldValues" except for the other dropdown. That function needs to get value of the first dropdown, say "drop1" for selecting the correct value out of the data set.
function SetFieldValuesDrop2(cSelFromDrop2) {
var cDrop1Sel = this.getField("drop1").value;
this.getField("DeptContact").value = DeptData[cDrop1Sel ].email.replace(/%%/,cSelFromDrop2);
You see you this works, each drop list contributes, so each has to use the others value on the select.
A different approach is to use calculation scripts in the target fields. This is fundamentally different than the one I suggest in the article and works like this
// email field calculation script
event.value = DeptData[this.getField("drop1").value].replace(/%%/,this.getField("drop2"));
I like this calculation script approach better.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now