I need to use the index from a for loop to check values in 10 columns QUESTION_1_ANSWER, QUESTION_2_ANSWER, QUESTION_3_ANSWER ... etc.return from jQuery Ajax.
Return surveyResults object: {question_1_Answer: 'Other', question_1_Other_Answer: 'Naples Florida', question_2_Answer: '', question_2_Other_Answer: '', question_3_Answer: '', …}
I tried to create a variable, however it does not work. Any thoughts?
({ type: 'POST',
url: 'getEmployeeSurveyResults.php',
dataType: 'json',
data: {surveyID: surveyID,
sessionEmployeeNumber: sessionEmployeeNumber,
},
cache: false,
success: function (data) {
$.each(data, function (i, surveyResults) {
for (i = 1; i < 11 ; i++) {
var surveyResultsQuestionAnswer='surveyResults.question_'+i+'_Answer'
console.log( 'surveyResultsQuestionAnswer: ' + surveyResultsQuestionAnswer );
if(surveyResultsQuestionAnswer !==''){
Do something ....
}
}
});
},
error: function(jqXHR, textStatus, errorThrown) {
alert('Error: ' + textStatus + ' ' + errorThrown)
}
}); //* End - $.ajax