I am trying to have my form fields submit after the onchange event.
The Json value returned looks like this:
{ "data": [ { "name":"p_data1,KEY=1", "value":"2", "error":"no error" } ] }
I am going to add an array to this sting to specify any other fields (such as 'total') which also need updating, like so:
{ "data": [ { "name":"p_data1,KEY=1", "value":"2", "error":"no error", "toUpdate": [ { "name":"p_total_data1" , "value":"999" } ] } ] }
So I will only want to run the update total script when the toUpdate array exsists. My issue is if I use an if statement like
if(typeof results.data[0].toUpdate[0].name == 'undefined'){}
or
if(null != results.data[0].toUpdate[0].name){}
or
if(results.data[0].toUpdate[0].name.length){}
All give the error "results.data[0].toUpdate[0].name is undefined". How can I test whether it is defined?