pTutorial

New way to learn Programming

Angularjs Radio Button Validation

HTML

<!DOCTYPE html> 
<html lang="en-US">
<head>
<script src="http://www.ptutorial.com/angularjs/
angular.min.js"></script>
</head>
<body>
<div ng-app="mainApp" >
<div ng-controller="ukController">

<p>Select gender</p>

Male: <input type="radio" ng-model="myForm.gen" 
value="Male"><br/>    
Female: <input type="radio" ng-model="myForm.gen" 
value="Female">   <br/> 
You are
<button ng-click="save()">save</button>
<div ng-show="flag">{{msg}}</div>
<p style="color:green";> </p>

</div>
</div>
</body>
</html> 


AngularJS

<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('ukController', function($scope) {
$scope.myForm = {};           
$scope.myForm.gen = '';   
$scope.flag=false;
$scope.msg=false;
$scope.save = function() {
if($scope.myForm.gen==''){
$scope.flag=true;
$scope.msg="Pleas select gender";       
alert($scope.msg);
}else{
$scope.flag=true;
$scope.msg="You Have choosen "+$scope.myForm.gen;      
alert($scope.msg);
}
}
});
</script>

Download

See Also


QUOTES OF THE DAY

Knowledge itself is a power.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER