The easiest way is to write a function that uses a basic loop and returns a Boolean value. Get the value of each input
field with $('#fieldId')
, compare it with your expected answers, and then base the next action on the value returned by the answer-checking function. Based on your example snippet, here's one way to do it:
var fields = ['r1c1', 'r1c2', 'r1c3', 'r1c4', 'r1c5'],
answers = ['A', 'B', 'C', 'D', 'E'];
var checkAnswers = function(fieldArray, answerArray) {
for (var i = 0; i < fieldArray.length; i += 1) {
if ($('#' + fieldArray[i] + '-input').val() !== answerArray[i]) {
// This field doesn't have the correct answer
return false;
}
}
// Made it all the way through the loop, so all answers match
return true;
}
if (checkAnswers(fields, answers)) {
// dialog X
} else {
// dialog Y
}