[RESOLVED] Get value chosen from select, display the value of the array with that same name.
I am working on a little project here. I have two arrays (States, Cities) I am trying to allow the user to chose one from a select form (Choice) and then have the values of the chosen array displayed in a alert(). Obviously I could just write an if statement and display the required content depending on whether the value selected == States or Cities. But this project is just a placeholder project for me to figure out one aspect of a much larger project I am working on. And it is important for the result to be chosen dynamically as in the final project I won't know the values that the select field is being filled with.
What I need to do is take the value returned from the select field (Choice) and turn that into the name of the array and display that. If I use this code
then it returns the values of that array. But like I said I need to be able to dynamically select what array to display based on users input
returns the value chosen. How can I take the value chosen and actually display the value of the array with that same name. In other words let JS know that I don't literally want it to display the value chosen but rather the value chosen is the name of the array I want it to display?
x = document.getElementById("Choice").value;
x is name of array;