I have the following JSON:
{"a":"111","b":"7"}
Also, I have a selectbox with value (a and b). I want to make it when user select "a", it will show "111" from the JSON while select "b", it will show "7".
I wrote the following jQuery, but the JSON value returned out is undefined.
<select id="selectbox" name="selectbox">
<option value="a" grouping="">A</option>
<option value="b" grouping="">B</option>
</select>
The field store the JSON value:
<input id="JSON" name="JSON" type="text" value="{"SickLeave":"111","AnnualLeave":"7"}">
My jQuery code:
$("select[name=selectbox]").on('change', function() {
var obj = JSON.parse($('[name$=JSON]').val());
var optionvalue = $("select[name=selectbox] option:selected").val();
console.log(optionvalue);
console.log(obj.optionvalue);
});
However, the "obj.optionvalue" is undefined.