AngularJs get checkbox value
home
Run
screen_rotation
fullscreen
cloud_download
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.selectedCheckboxes = ''; $scope.getSelectedCheckboxes= function(myCheckbox) { // copy data //alert(myCheckbox); $scope.selectedCheckboxes = angular.copy(myCheckbox); // or you can get the checkbox values individually as below // $scope.value1 = myCheckbox.value1; // $scope.value2 = myCheckbox.value2; // $scope.value3 = myCheckbox.value3; // $scope.value4 = myCheckbox.value4; }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form action="javascript:void(0)"> Checkbox1 : <input type="checkbox" name="checkbox1" ng-model='myCheckbox.value1' /><br /> Checkbox2 : <input type="checkbox" name="checkbox2" ng-model='myCheckbox.value2' /><br /> Checkbox3 : <input type="checkbox" name="checkbox3" ng-model='myCheckbox.value3' /><br /> Checkbox4 : <input type="checkbox" name="checkbox4" ng-model='myCheckbox.value4' /><br /> <button ng-click="getSelectedCheckboxes(myCheckbox)">Get Value</button> </form> <p>Selected Checkboxes = {{selectedCheckboxes | json}}</p> <p>Value1 = {{selectedCheckboxes.value1}}</p> <p>Value2 = {{selectedCheckboxes.value2}}</p> <p>Value3 = {{selectedCheckboxes.value3}}</p> <p>Value4 = {{selectedCheckboxes.value4}}</p> </div> </div> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script> <script> var myApp = angular.module("myApp", []); myApp.controller("myController", function($scope) { $scope.selectedCheckboxes = ''; $scope.getSelectedCheckboxes= function(myCheckbox) { // copy data //alert(myCheckbox); $scope.selectedCheckboxes = angular.copy(myCheckbox); // or you can get the checkbox values individually as below // $scope.value1 = myCheckbox.value1; // $scope.value2 = myCheckbox.value2; // $scope.value3 = myCheckbox.value3; // $scope.value4 = myCheckbox.value4; }; }); </script> </head> <body> <div ng-app="myApp"> <div ng-controller="myController"> <form action="javascript:void(0)"> Checkbox1 : <input type="checkbox" name="checkbox1" ng-model='myCheckbox.value1' /><br /> Checkbox2 : <input type="checkbox" name="checkbox2" ng-model='myCheckbox.value2' /><br /> Checkbox3 : <input type="checkbox" name="checkbox3" ng-model='myCheckbox.value3' /><br /> Checkbox4 : <input type="checkbox" name="checkbox4" ng-model='myCheckbox.value4' /><br /> <button ng-click="getSelectedCheckboxes(myCheckbox)">Get Value</button> </form> <p>Selected Checkboxes = {{selectedCheckboxes | json}}</p> <p>Value1 = {{selectedCheckboxes.value1}}</p> <p>Value2 = {{selectedCheckboxes.value2}}</p> <p>Value3 = {{selectedCheckboxes.value3}}</p> <p>Value4 = {{selectedCheckboxes.value4}}</p> </div> </div> </body> </html>
Copyrights@tutorialsplane.com