I am writing html and javascript code to get some data from a Json file. My html code:
<div class="section">
<div class="sectionTitle">
<h3>Configuration</h3>
</div>
<select name="selectDistribution" class="span12" onchange="callDist("value");"
onfocus="this.selectedIndex = -1;">
<option >Choose from distributions.</option>
<option value="1">Uniform</option>
<option value="2">Normal</option>
<option value="3">Exponential</option>
<option value="4">Geometric</option>
</select>
<div id="parameters"></div>
<div id="distributionParams"> </div>
<button class="btn btn-large btn-block btn-primary" type="button">Send</button>
</div>
When a user chooses one distribution the parameters must be shown below the selection. For example when the user selects Uniform distribution min and max values must be attached below and I want to show first min value label and its value in text box,and for the max value the process is the same.
My callDist() function function callDist(type) {
$.getJSON('Dist.json', function(type){
var $container = $('#parameters').empty();
$.each(type.distributions, function(i, distributions) {
if(type==1){
$.each(distributions.type, function(key, value) {
$container.append(key + ': ' + value + '<br />');
}
//And so on...
});
$container.append('<hr />');
}
);
});
}
And my Dist.Json file is below:
{
"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}],
}
]
}
How can show the parameters just after the user selects one of the distributions and show the parameters in dynamically created labels and textboxes. Thanks.