[
{ "id":"1","firstName":"John", "lastName":"Doe","role":"engineer","age":"25" },
{ "id":"2","firstName":"Jax", "lastName":"Ali","role":"Software engineer","age":"35" },
{ "id":"3","firstName":"Suz", "lastName":"Ibra","role":"Developer","age":"23"},
{ "id":"4","firstName":"Alia", "lastName":"Arnold","role":"UX Designer","age":"28"},
{ "id":"5","firstName":"Jack", "lastName":"Jones","role":"Programmer","age":"37"}
]
<html>
<head>
<meta charset="utf-8" />
<title>Testside</title>
<script>
window.onload = oppstart;
var laster; //xmlhttp
var person;
function oppstart() {
laster = new XMLHttpRequest();
var filnavn = "data.json" +"?id="+Math.random();
//alert(filnavn);
laster.open("GET",filnavn,true);
laster.onreadystatechange = ferdigLastet;
laster.send();
}
function ferdigLastet() {
if(laster.readyState === 4 && laster.status === 200) {
person = JSON.parse(laster.responseText);
for (var i = 0; i < person.length; i++) {
document.getElementById("nedtrekk").innerHTML+= "<option value='" + person[i].id +"'>" + person[i].firstName +"</option>"
}
}
}
</script>
</head>
<body>
<select name="id" id="nedtrekk">
</select>
<p id="utskrift"></p>
</body>
</html>
How do i tell my code to get information from the selected option list name?
So if i select JACK from my option list i want my code to give me his information from my JSON file. What it currently gives me is the option values but not the information in my <p> tag
tag` - I cannot see any code that **currently** retrieves any information upon making a selection. Where is that code? and why would you expect the `
` tag to be part of your option? It sits external to the select. I'm lost.
– Nope Dec 01 '17 at 14:46