javascript - How can I pass select value to another function and get data from Json according to passed value? -


I am writing html and javascript code to get some data from a JSON file. My HTML code:

  & lt; Div class = "section" & gt; & Lt; Div class = "sectionTitle" & gt; & Lt; H3 & gt; Configuration & lt; / H3 & gt; & Lt; / Div & gt; & Lt; Select name = "select distribution" category = "span 12" onchange = "callDist (" value ");" Onfocus = "this.selectedIndex = 1;" & Gt; & Lt; Options & gt; Choose from Distribution. & Lt; / Options & gt; & Lt; Option value = "1" & gt; Uniform & lt; / Option & gt; & Lt; Option value = "2" & gt; General & lt; / Options & gt; & Lt; Option value = "3" & gt; Exponential & lt; / Options & gt; & Lt; Option value = "4" & gt; Geometric & lt; / Options & gt; & Lt; / Select & gt; & Lt; Div id = "parameter" & gt; & Lt; / Div & gt; & Lt; Div id = "dispersion" & gt; & Lt; / Div & gt; & Lt; Button class = "BTN BTN-Large BTN-Block BTN-Primary" type = "button" & gt; Send & lt; / Button & gt; & Lt; / Div & gt;   

When a user selects a distribution then the parameter should be shown below the selection. For example, when the user selects uniform delivery minutes and the maximum value must be attached below and I want to show the value in the minimum price label and text box first, and the process for the maximum value is the same.

My callDist () function function callDist (type) {

  $ GetJSON ('Dist.json', function (type) {var $ container = $ ('# parameter') empty (); $ .eich (type dysthibition, function (i, distribution) {if (type == 1) { $ Keach (distribution. type, function (key, value) {$ container. append (key + ':' + value + '& lt; br / & gt;');} // and so on ...} ); $ Container.append ('& lt; hr / & gt;');});}); }   

and my Dist.Json file is below:

  {"distribution": [{"name": "uniform", "type": "" "parameters": "[2]", "parameters": [{ "minValue": "2", "maxValue": "4"}}}, { "name": "normal", "type": "", "Parameter": ["mean": "5", "standbet deviation": "3"},}, {"name": "exponential", "type": "3", "parameter" : [{ "lamda": "2"}],} { "name": "geometric", "type": "4", "parameters": [{ "probability": 0.2}],}]}   

after selecting one of the user's delivery and showing dynamically created labels and parameters in the text box How can the parameters be shown after assignment? Thank you.

Try this code ...

  function callDist (value) ) {$ .getJSON ('Dist.json', function (type) {for distribution in i type} {if (type.distributions [i] .name == value) {for (type in j. Type.distributions [I] in. parameter () in {type.Distributions [k]. the parameter [j]) {var val1 = distribution [I]. parameter [J] [a]; var val2 = distribution [I]. parameter [J] [ ];}}}}}); }    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -