JavaScript error with displaying previously stored data
I have two tables. The first table has form ields like ID, Result (option from a drop down), Details (open text field), Score (number). Based on an answer ("N/C") selected in Result and that row's Score, I want the 2nd table to sort descending and display the ID (into DefectID) and Details (into DefectDetails) (in respective read-only form fields) from each row that had "N/C" selected in Result.
I have checked my field names and all numbering starts at 0. I think I am close, but I get errors when trying to figure out how to call previously stored information. It's throwing errors on the forEach loop. Most recent error is ReferenceError: invalid assignment left-hand side. Here's what I have...
var defectObjs = []; // empty array to store details
for (i = 1; i < 6; i++) {
if (this.getField(Result).value == "N / C") { // checking if n/c
defectObjs.push({
RefID: "RefID" + i});
({ Details: "Details" + i});
({ Score: "Score" + i});
};
// Sort defectObjs
defectObjs.sort((x, y) => {
if (x.Score > y.Score)
return 1;
else if (y.Score > x.Score)
return -1;
else
return 0;
});
// forEach on defectObjs that starts counting at 0.
defectObjs.forEach((item, index) => {
"DefectID"+index = item.RefID;
"DefectDetails"+index = item.Details;
});Thanks in advance for any wisdom you can provide!
