I have the code below, which I am using to create a table and then populate it with data from JSON. My issue is that I have several data objects and would like to switch between them using select tag. Could you please help?
HTML
<select name="selector" onchange="onDataChange();">
<option value="data1">RD1</option>
<option value="data2">RD2</option>
<option value="data3">RD3</option>
</select>
JSON Data
var data1 = [
{"value":"RD01"},
{"value":"RD02X"},
{"value":"RD021ZX"}
];
var data2 = [
{"value":"AX761"},
{"value":"GT02X"},
{"value":"GB051ZX"}
];
var data3 = [
{"value":"BG761"},
{"value":"OP02Z"},
{"value":"FBL1ZX"}
];
JQuery
function onDataChange(){
var select = $("select[name=selector]").val();
//some logic
}
function buildTable(){
var table = $(".code-table");
for(i = 0; i < data.length; i++){
var row = "<tr><td>" + data[i].value + "</td></tr>";
table.append(row);
}
}
buildTable();
var