How to get selected radio button value in AngularJS?




How to get selected radio button value in AngularJS?

I will help to get checked radio button value in angular js app. we can get selected radio button value in controller of angular.

Here we will create simple example. we will create simple for and submit button. When you click on submit button then one angular controller method will call and we will get selected radio button value using angularjs $scope variable.

Also Read:- How to add Days, Hours, Minutes, and Seconds to Datetime in PHP

<!doctype html>
<html>
   <head>
      <title>How to get selected radio button value in AngularJS?</title>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
   </head>
   <body ng-app='myapp'>
      <h1>How to get selected radio button value in AngularJS?</h1>
      <div ng-controller="myCtrl">
         <div class="radio">
            <label><input type="radio" ng-model='sex' ng-value='"male"' name="sex">Male</label>
         </div>
         <div class="radio">
            <label><input type="radio" ng-model='sex' ng-value='"female"' name="sex">Female</label>
         </div>
         <button ng-click="submitResult()">See Result</button>
      </div>
   </body>
   <script type="text/javascript">
      var app = angular.module('myapp', []);
      app.controller('myCtrl', function ($scope, $location) {
         $scope.sex = 'male';
         $scope.submitResult = function() {
            alert($scope.sex);
         };
      });
   </script>
</html>

 



Author Biography.

Lokesh Gupta
Lokesh Gupta

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working in the information technology and services industry. I enjoy solving complex problems within budget and deadlines putting my skills on PHP, MySQL, Python, Codeigniter, Yii2, Laravel, AngularJS, ReactJS, NodeJS to best use. Through Knowledge of UML & visual modeling, application architecture design & business process modeling. Successfully delivered various projects, based on different technologies across the globe.

Join Our Newsletter.

Subscribe to CrowdforThink newsletter to get daily update directly deliver into your inbox.

CrowdforJobs is an advanced hiring platform based on artificial intelligence, enabling recruiters to hire top talent effortlessly.

CrowdforJobs

CrowdforApps brings to you the well researched list of the most successful and finest App development companies, Web software developers.

CrowdforApps

CrowdforGeeks is where lifelong learners come to learn the skills they need, to land the jobs they want, to build the lives they deserve.

CrowdforGeeks

CrowdforThink is a leading Indian media and information platform, known for its end-to-end coverage of the Indian startup ecosystem.

CrowdforThink
CFT

News & Blogs

b155c4808d155c5ed54a2d70f917f6ea.png

An Introduction to Angular: The Remarkable JS F...

Javascript frameworks have nowadays become the most popular and most-used web app development sol...

2cda7519f703462a0eabd1c2e84e0001.jpg

Why shouldn’t you wait to jump onto Angular 2?

AngularJs is a JavaScript framework and is widely adopted framework in building Single Page Web A...

4daa46c3764dd609db4614aa99fec114.png

AngularJS: Factory vs Service vs Provider

When you initially begin with Angular, you’ll normally wind up flooding your controllers an...

Top Authors

Hey, I am Suraj - a full-time blogger and a social media expert currently working on the Growth H...

Suraj Kumar

With good communication and writing skiils, Astha Sharma is a full-time content writer working wi...

Astha Sharma

Overall 3+ years of experience as a Full Stack Developer with a demonstrated history of working i...

Lokesh Gupta

Aditya Sehgal is a recognised financial adviser, tech and gadget writer and blogger. Still he has...

Aditya Sehgal
CFT

Our Client Says

WhatsApp Chat with Our Support Team