2

In view there are two lists of radio buttons

L1

    <input type="radio" name="SET1" ng-model="SET1Selected" value="S1"> S1
    <input type="radio" name="SET1" ng-model="SET1Selected" value="S2"> S2
    <input type="radio" name="SET1" ng-model="SET1Selected" value="S3"> S3

L2

    <input type="radio" name="SET2" ng-model="SET2Selected" values="S4"> S4
    <input type="radio" name="SET2" ng-model="SET2Selected" value="S5"> S5
    <input type="radio" name="SET2" ng-model="SET2Selected" value="S6"> S6

    <button ng-click="submitRadioBtn()"></button>

Angular JS

    var app = angular.module("myApp", []);
    app.controller("myCtrl", ['$scope', function($scope) {  

     $scope.submitRadioBtn=function(){
       var valfromSET1 = $scope.SET1Selected;
        var valfromSET2 = $scope.SET2Selected; 
     }
    }]);  

I have to get values of both radio buttons on click.

4
  • your code looks true, because you have 2 different groups seting to 2 different variables Commented Jan 29, 2017 at 12:32
  • can you show us the output? Commented Jan 29, 2017 at 12:33
  • How about setting an ng-value instead of value? like in here stackoverflow.com/questions/32450288/… Commented Jan 29, 2017 at 12:37
  • @Salman.. getting $scope.SET1Selected as undefined Commented Jan 29, 2017 at 12:42

1 Answer 1

0

Your code should work without any problem. Just make sure you have included the ng-controller outside both of the div tags.

DEMO

 var app = angular.module("myApp", []);
 app.controller("myCtrl", ['$scope', function($scope) {

   $scope.submitRadioBtn = function() {
     var valfromSET1 = $scope.SET1Selected;
     var valfromSET2 = $scope.SET2Selected;
     console.log(valfromSET1);
     console.log(valfromSET2);
   }
 }]);
<!DOCTYPE html>
<html ng-app="myApp">

<head>
  <meta charset="utf-8" />
  <script src="https://code.angularjs.org/1.4.7/angular.js"></script>
  <script src="app.js"></script>
</head>

<body ng-controller="myCtrl">
  <div class="row">
  <input type="radio" name="SET1" ng-model="SET1Selected" value="S1"> S1
  <input type="radio" name="SET1" ng-model="SET1Selected" value="S2"> S2
  <input type="radio" name="SET1" ng-model="SET1Selected" value="S3"> S3
  </div>
  <div class="row">
  <input type="radio" name="SET2" ng-model="SET2Selected" values="S4"> S4
  <input type="radio" name="SET2" ng-model="SET2Selected" value="S5"> S5
  <input type="radio" name="SET2" ng-model="SET2Selected" value="S6"> S6
  </div>
  <div class="row">
  <button ng-click="submitRadioBtn()">submit</button>
  </div>
</body>

</html>

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

Comments

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.