Multi-line Dropdown List Autopopulate
Hi everyone,
I have been working on accomplishing a task, that while I have the know-how on completing, is too large for my needs. Looking to see if someone has an idea on how to make this smaller in size as to reduce bogging down the form.
Here is what I am doing. I have a medical form I need to complete. It is a list of medications. Each row has medication name, dosage, frequency, side effects, etc. I have a dropdown list for the medications - the list contained 43 common medications with an "Other" so it can be added if necessary. According to the medication chosen, three other fields in the same row are autopopulated - common medication name, what it treats, and side effects.
The code I wrote works great. The problem is it is quite large with 43 medications. The page contains 11 rows. I would need to change the code for each row for it to autopopulate the corresponding fields. Is there an easier way to populate each row without needing to change each line of code according? It would be enormous with how I am doing it. Please, help me make it a bit more efficient. 😃
var MedData = {
"Medicine 1":{ addmed: "Tylenol", purpose: "Headache/Fever", sides: "Nausea, cramps" },
"Medicine 2":{ addmed: "Advil", purpose: "Pain/Fever", sides: "Side 1, 2, 3" },
"Medicine 3":{ addmed: "Aspirin", purpose: "Blood Thinner/Headache", sides: "Side 3, 2, 4" },
"Medicine 4":{ addmed: "Vitamin C", purpose: "Supplement", sides: "Side 3, 5, 4" }};
function SetFieldValues(cMedList) {
this.getField("Med1").value = MedData[cMedList].addmed;
this.getField("Purpose1").value = MedData[cMedList].purpose;
this.getField("Field2").value = MedData[cMedList].sides;
}
Many thanks and I look forward to another set of eyes.
Stephanie
(I am not sure why the formatting on the code is messing up when I post. Sorry!)
