I am trying to make a selection form, where depending on the select field chosen, I want different information to appear. Here is the way I'd like to represent it:
<form id="myForm">
<select name="options" form="myForm">
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
</select>
</form>
<!-- The following will be invisible until selection choice is made -->
<h1>option.name</h1>
<p>option.info</p>
Then, in JSON, I'd like the store the following content. I am using this as the handler just to test it out:
<script>
var data = {
"option1" : {
"name" : "Option 1",
"info" : "I'm glad you've chosen Option 1"
},
"option2" : {
"name" : "Option 2",
"info" : "Not a bad choice, either"
}
};
var myForm = document.getElementById('options');
myForm.addEventListener("change", function() {
val = this.value;
alert(data[val][name]);
}, false);
})();
</script>
The output of the alert is empty.