My javascript code;
function callDist(sel)
{
$.getJSON('Dist.json', function(data){
var $container = $('#parameters').empty();
$.each(data.distributions, function(i, distribution){
$.each(distribution, function(key,value)
{
if(distribution.type==sel.value) {
alert(distribution.name);
$.each(distribution.parameters, function(key, value) {
$container.append(key + ':' + value + '<br />');
$container.append('<hr />');
});
}
});
}
);
});
}
My Json code;
{
"distributions":[
{
"name":"Uniform",
"type":1,
"parameters":[{ "minValue":2 , "maxValue":4 }]
},
{ "name":"Normal",
"type":2,
"parameters":[{ "mean":5 , "standartDeviation":3 }]
},
{
"name":"Exponential",
"type":3,
"parameters":[{"lamda":2}]
},
{
"name":"Geometric",
"type":4,
"parameters":[{"probability":0.2}]
}
]
}
Html code;
<select name="selectDistribution" class="span12" id="Options"
onchange="callDist(this);" >
<option value="0">Choose one distribution</option>
<option value="1">Uniform</option>
<option value="2">Normal</option>
<option value="3">Exponential</option>
<option value="4" >Geometric</option>
</select>
In Json there is an array that created by some distributions.when the user selects some of them from select option I am triggering callDist(sel) function. When the passed value sel is equal to distribution.type , I want to write the parameters of that distribution to a div.How can I do that?Thanks.
JSON, as that will override the nativeJSONobject. And what have you tried to accomplish your task?sel.valuesupposed to be?