As a newcomer to Javascript (although I have a strong grasp of php), I'm experimenting with using associative arrays to accomplish two tasks.
The first task is successfully populating a dropdown menu:
var select = document.getElementById('FName');
var options = fNames;
for(var i = 0; i < (options.length-1); i++) {
var opt = options[i];
var el = document.createElement("option");
el.textContent = opt;
el.value = opt;
select.appendChild(el);
}
The 'fNames' variable consists of an array of strings sourced from a php array. Additionally, there is another array named 'fDesc' that is structured to align with the 'fNames' array as follows:
var fNames = ["aName", "bName", "cName"]
var fDesc = ["aDesc", "bDesc,", "cDesc"]
At present, these are distinct arrays rather than a single multidimensional array.
I am looking for a method to display "aDesc" in a text box upon selecting "aName" from the dropdown menu. How can this be achieved?