My form consists of 5 questions, each with 3 different answers to choose from.
For example: q1. What is your favorite color?
Radio button-1: blue Radio button-2: red Radio button-3: grey
While most questions offer the same values (blue, red, grey), I am looking to calculate the total count of each value selected at the end of the form in order to determine if the respondent aligns with any of these values (blue, red, or grey).
I am developing this form using angularjs and here is my current progress:
<label>Q1. What is your favorite color?</label>
<div class="form-group">
<div class="radio">
<label>
<input type="radio" ng-model="formData.color" value="blue">
Blue
</label>
</div>
<div class="radio">
<label>
<input type="radio" ng-model="formData.color" value="red">
Red
</label>
</div>
<div class="radio">
<label>
<input type="radio" ng-model="formData.color" value="grey">
Grey
</label>
</div>
This portion of code only functions correctly if the values are already stored in the variable.
$scope.formData = { };
$scope.formData = [];
$scope.formData.sort();
var current = null;
var cnt = 0;
for (var i = 0; i < $scope.formData.length; i++) {
if ($scope.formData[i] != current) {
if (cnt > 0) {
console.log(current + ' appears ' + cnt + ' times');
}
current = $scope.formData[i];
cnt = 1;
} else {
cnt++;
}
}
if (cnt > 0) {
console.log(current + ' appears ' + cnt + ' times');
}