so got pretty far in quest fill in values , such using javascript, i'm bit stuck. i'm pretty sure i'm referencing right, html table isn't outputting anything.
basically i'm trying insert values json api retrieves out , insert values table using double for-loop (outer loop cycles through find perf_data , inner loop cycle through find values each instance) go through json file, , depending upon values, if value above 7, change color.
using json file:
{ "product" : [ { "name" : "txp", "id" : "txp", "measurement" : [ { "id" : "222222", "alias" : "site login", "perf_data" : [ { "name" : "last_five_minute", "value" : "4.908", "duration" : "300", "unit" : "seconds" }, { "name" : "last_fifteen_minute", "value" : "3.99", "duration" : "900", "unit" : "seconds" } ], "avail_data" : [ { "name" : "last_five_minute", "value" : "100", "duration" : "300", "unit" : "percent" }, { "name" : "last_fifteen_minute", "value" : "100", "duration" : "900", "unit" : "percent" }, { ... the .js file:
var jsondata = new xmlhttprequest(); var url = "---"; function changecolor(input, value){ if (value < 7) { $(input).removeclass(); $(input).addclass('high'); } } jsondata.onload = funtion() { if (jsondata.status === 200){ responseobject = json.parse(jsondata,responsetext); var newcontent = ''; (var = 0; < responseobject.perf_data.length; i++) { if (measurement.id === '222222') { (var x = 0; x < responseobject.value.length; x++) { newcontent += '<td id = "part">'+changecolor(responseobject.value[x]) +'</td>'; } document.getelementbyid('content').innerhtml = newcontent; } } } }; jsondata.open("get",url,true); jsondata.send(); my question boils down if i'm using double for-loop right go through json file? feel error might be, seems i'm referencing address of json file right bunch of examples i've seen simpler json referencing... or else?
thanks in advanced.
you missed lot of properties in way. work, don't know if makes sense (unknown us) problem need solve
for (var = 0; < responseobject.product[0].measurement.length; i++) { if (responseobject.product[0].measurement[i].id === '222222') { (var x = 0; x < responseobject.product[0].measurement[i].perf_data.length; x++) { newcontent += '<td id = "part">'+changecolor(responseobject.product[0].measurement[i].perf_data[x].value) +'</td>'; } document.getelementbyid('content').innerhtml = newcontent; } }
Comments
Post a Comment