mercredi 28 juin 2017

retrive value from multiple checkbox in html using angularJS

I have a scenario where any one protocol has to be configured on a device. A web UI will display all the options as a checkbox and I need to retrieve the protocol and device that was checked and send this data via http post to backend server. I am using HTML and AngularJS. Below is my code so far and please suggest if this can be done in a better way.

var Myapp = angular.module('Myapp', []);


Myapp.controller('CloudController', function($scope,$http)
        {
        $scope.execute = function(ImageLoc, protocol, device)
            {
           # HTTP request will be generated here        
            };
          });
<form>
<h3>Choose the protocol:</h3>
  <input type="checkbox" name="protocol" value=1> L3 Sanity <br>
  <input type="checkbox" name="protocol" value=2> L2 Sanity <br>
  <input type="checkbox" name="protocol" value=3> ROUTING <br>
  <input type="checkbox" name="protocol" value=4> STP <br>
  <input type="checkbox" name="protocol" value=5> VLAN <br>
  <input type="checkbox" name="protocol" value=6> Interface Scale <br>
  <input type="checkbox" name="protocol" value=7> VLAN SCALE <br>
  
<h3>Choose the Device:</h3>
  <input type="checkbox" name="device" value=1> DUT 1 <br>
  <input type="checkbox" name="device" value=2> DUT 2 <br>
  <input type="checkbox" name="device" value=3> DUT 3 <br>
  <input type="checkbox" name="device" value=4> DUT 4 <br>
  <input type="checkbox" name="device" value=5> DUT 5 <br>
  
<h3>Enter Image location:</h3> 
  <input type="text" ng-model="ImageLoc" />
  
  <p><input type="button" value="Launch" ng-click="execute(ImageLoc,protocol,device)"/></p>
</form>



Aucun commentaire:

Enregistrer un commentaire