1

I have questioner form, in their question have multple options. how to get user selected options?

Here is the code?

         ...
         <ul>
            <li ng-repeat="question in questionPaper.questions">
              <div>{{question.description}}</div>
              <ul>
                <li ng-repeat="option in question.options">
                  <span>
                <input type="radio" name="option_question_{{question.id}}" ng-model="option.id"/>
                {{option.description}}
              </span>
                </li>
              </ul>
            </li>
          </ul>
         ...

How to get option values as

{question_paper_id: 1, answers: [{question_id: 1, options_id: 23}, {question_id: 2, options_id: 21}, {..}] }   

Here is my code in plnkr http://plnkr.co/edit/OTDsUUCiDGYfxJ2AMzFR

2 Answers 2

1

Basically, you can dynamically add a property when the radio button is selected:

<input type="radio" ng-model="question.selected_id" ng-value="option.id"/>

$scope.selected_ids = [];
$scope.submitAnswers = function() {
    angular.forEach($scope.questionPaper.questions, function(question) {
        $scope.selected_ids.push(question.selected_id);
    });
}

Take a look at the demo: http://plnkr.co/edit/QG8XP0jfjyJPY1xaXx6d?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

everything else seems to fine. just replace your script tag for including angular with this

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>

1 Comment

Please check the code in plnkr, In the form there is multiple radio button options for each question, How map the answer(user selected radio button option) to respective question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.