This is my code:
<input type="password" id="centraPassword" placeholder="Enter Centra Password" class="form-control" ng-model="centraPassword" /> <label> <input type="checkbox" ng-model="centrapasswordcheck" > I have a Centra Travels password </label> <button type="submit" class="btn btn-info" ng-disabled="continueEmailButton" id="btnContinue" ng-click="ContinueDetails()">Continue</button>
This is my angularjs Code:
$scope.ContinueDetails = function () { if ($scope.centrapasswordcheck == true) { if ($scope.centraPassword == '' || $scope.centraPassword == null) { alert("please enter your password") return; } } }
In the above code when I click the Continue button, first check the checkbox checked or not after it will check enter the password or not.
Advertisement
Answer
var module = angular.module('myApp', []); module.controller('myCtrl', function($scope) { $scope.centrapasswordcheck = true; $scope.ContinueDetails = function () { if ($scope.centrapasswordcheck == true) { if ($scope.centraPassword == '' || $scope.centraPassword == null) { alert("please enter your password 1"); } else { alert("Password Validated"); } } else { alert('Please Check Checkbox'); } alert('Coming out of the fuction'); } });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <body ng-app="myApp" ng-controller="myCtrl"> <input type="password" id="centraPassword" placeholder="Enter Centra Password" class="form-control" ng-model="centraPassword" /> <label> <input type="checkbox" ng-model="centrapasswordcheck" > I have a Centra Travels password </label> <button type="submit" class="btn btn-info" ng-disabled="!centrapasswordcheck" id="btnContinue" ng-click="ContinueDetails()">Continue</button> </body>
Check Once Is it what you want or something else
Remove alerts ands code what you want