Let's assume I'm pulling from an XML page formatted like so:
<people>
<person>
<name>Bob</name>
<age>45</age>
<hobby>Programming</hobby>
</person>
....
</people>
If I have a function that reads XML data into a JavaScript variable like so:
...
var data = responseXML;
...
And an HTML dropdown dynamically populated with the names from the data variable (the options would be added via JavaScript using an onload call on the body. Before the page loads, the code wouldn't actually contain the option tags as seen below):
<select id="names" onchange="getInfo()">
<option value="Bob">Bob</option>
<option value="Jim">Jim</option>
<option value="Ron">Ron</option>
</select>
While using the onchange call on select, how can I dynamically list out the information about the person selected from the dropdown into an unordered list?
If Bob was selected, output would look something like this:
Name: Bob
Age: 45
Hobby: Golf
If a new person was selected from the dropdown, their information would then be displayed. Given the code I already have, if a new person was added to the XML document, they would automatically be added to the dropdown, so their information should be able to automatically be displayed if selected without having to add any additional code.
I would prefer to use JavaScript over jQuery as that is what I'm using for reading the XML document data into the JavaScript data variable.