Francis Empleo Francis Empleo - 1 year ago 77
AngularJS Question

Get values of dynamic fields and radio button

can you give ideas or suggestions about this problem.

im creating four radio buttons per question(a multiple choice question basically)and they are generated dynamically. if i created 3 questions that are multiple choice, 3 multiple choices will be displayed in my questionnaire.
if 3 multiple choice questions exist, 3 questions x 4 radio buttons = 12 radio buttons. this means i have a 3 set radio group consisting of four radio buttons. my problem, how can i get the values selected in the 3 sets of radio group?

php code:
echo "<li><input type='radio' name='radio' value='a' class='answer multiple'/>choice</li>";
echo "<li><input type='radio' name='radio' value='b' class='answer multiple'/>choice</li>";
echo "<li><input type='radio' name='radio' value='c' class='answer multiple'/>choice</li>";
echo "<li><input type='radio' name='radio' value='d' class='answer multiple'/>choice</li>";

Answer Source

You can do it by using ng-repeat to create multiple questions and then a nested ng-repeat to display the choices

Here is the plnkr for the same

  <div ng-repeat="question in questions">
    <div ng-repeat="choice in question.choices"><input type="radio" ng-name="question.title" ng-model="radioValue[$parent.$index]" ng-value="choice">{{choice}} </div>

AngularJS Code

$scope.questions = [{id:1, title:'Question 1', choices:['Apple','Orange','Mango','Guava']},
                    {id:2, title:'Question 2', choices:['Apple2','Orange2','Mango2','Guava2']},
                    {id:3, title:'Question 3', choices:['Apple3','Orange3','Mango3','Guava3']}]
   $scope.radioValue =[];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download