I want to get the value of the list id. Then access the object property. For example, if egg is chosen: I want to get egg.cost ( which is 9)
However, it is coming up as undefined.
HTML portion :
<select id = "list">
<option value = "egg">Eggs</option>
<option value ="banana">Banana</option>
</select>
</select>
<button onclick ="getSelectValue()"></button>
<div id ="example">testing</div>
javascript:
function getSelectValue(){
var selectedValue = document.getElementById("list").value;
document.getElementById("example").innerHTML=selectedValue["cost"];
}
var banana = {
cost:1.39,
servings:6,
servingSize:1,
costPerServing:.23
};
var egg = {
cost:9,
servings:24,
servingSize:1,
costPerServing:.38
};