jquery - Dropdown combination in javascript -
i new javascript. trying make drop-down combination work project apparently not working. can please check error in code.
this html code.
<select id="chartselect" onchange="changechart(this.value);"> <option value="line">line chart</option> <option value="pie">pie chart</option> <option value="map">choropleth map</option> </select> <select id="dataselect" onchange="changedata(this.value);"> <option value="house">house data</option> <option value="toilet">toilet data</option> </select>
and javascript portion;
function changechart(ele){ var value = chartselect.options[chartselect.selectedindex].value; if (value==="pie"){ var datatype = dataselect.options[dataselect.selectedindex].value; if (datatype === "house"){ alert("this pie chart(house)"); } if (datatype === "toilet"){ alert("this pie chart(toilet)"); } } if(value=="line"){ var datatype = dataselect.options[dataselect.selectedindex].value; if(datatype == "house"){ alert("this line chart(house)"); } if (datatype == "toilet"){ alert("this line chart(toilet)"); } } };
this link jsfiddle.
you have 1 more error in changedata() function not defined, , 1 more thing changechart(this.value); there no use of this.value in side function, have refined code error free.fiddle demo
function changechart() { var value = chartselect.options[chartselect.selectedindex].value; if (value == "pie") { var datatype = dataselect.options[dataselect.selectedindex].value; if (datatype == "house") { alert("aakarshan") } if (datatype == "toilet") { alert("dhakal") } } if (value == "line") { var datatype = dataselect.options[dataselect.selectedindex].value; if (datatype == "house") { alert("bivav") } if (datatype == "toilet") { alert("satyal") } } }
Comments
Post a Comment