i have created a javascript function to take json variables and do 'Stuff' with them http://jsfiddle.net/57fXb/1/#&togetherjs=5vxD5KeLBa
Here is the function code
function Machinecycle(ZW, Number) {
var machines = {
"Machines": [
{"cycle":1,"percent":1},
{"cycle":2,"percent":-2},
"cycle":3,"percent":3}
]
};
// obj = JSON.parse(machines);
var cycle = machines.Machines[Number].cycle;
var percent = machines.Machines[Number].percent;
if (cycle < 480) {
document.getElementById('ZW01001').style.backgroundColor = 'lime';
document.write(cycle);
document.write(percent);
} else {
document.getElementById('ZW01001').style.backgroundColor = 'red';
}
}
When running this code as Machinecycle('ZW01001',0): ZW01001 being the Id of the Div and 0 being the records that is needed out of the JSON i get the error
Uncaught TypeError: Cannot read property 'style' of null
which i am assuming that is because it cant find the Div with the Id given to the function but i cant figure out why, this is running in it's own JavaScript file, however i also tried it in the html file with no success any help would be much appropriated