Javascript assignment issue

Not technically a Canvas question.
I am returning a field name and field value from a database query. What I want to do is set the value of the field on the HTML form to the value returned. I can build the field name but I can’t seem to then use that field name to set the value. See the code below.

field = “document.enteredValues.” + response.DATA[i][2] + k.toString();
field.value = response.DATA[i][3];

The field value resolve to something like document.enteredValue.draglineOB1
In JavaScript normally document.enteredValue.draglineOB1.value = 12 would normally work.
I have tried to use the eval(), but JavaScript does not like on the left hand side of a function.

Hi @bknott,

Is this in a Canvas app? The first assignment creates a string variable but in the second you try to add a property called value. You can’t do both.

No its not a Canvas app. Its just Angular JS. I’m trying to build a form field name from a database variable and then set the value of the field on the form. The ‘field’ when printed contain the correct name, I need to evaluate that field and set the value of the the evaluated field value.

Worked it out.

$scope[response.DATA[i][2] + k.toString()] = response.DATA[i][3];