0

How can I send the text from selected checkbox to the div with selected-checkbox class?

For example, if I click on the first checkbox the div should get the text "First label".

JSFIDDLE

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<label>First label</label>
<input type="checkbox" />

<label>Second label</label>
<input type="checkbox" />

<label>Third label</label>
<input type="checkbox" />

<div class="selected-checkbox"></div>

2 Answers 2

2

I updated a fiddle. Please use below link https://jsfiddle.net/itsramesh/8jauzmtm/4/

Using angular ng-true-value attribute directive for checkboxes you can set label name to div.

Sign up to request clarification or add additional context in comments.

Comments

0

enter image description here

<script> 
angular.module('myApp',[]);
angular.module('myApp',[]).controller('MyController',function($scope){
$scope.obj={};
})
</script>

<div ng-app="myApp" ng-controller="MyController">
<label>First label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="First label" ng-false-value=""/>

<label>Second label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="Second label" ng-false-value=""/>

<label>Third label</label>
<input type="checkbox" ng-model="obj.first" ng-true-value="Third label" ng-false-value=""/>

<div class="{{obj.first}}">{{obj.first}}</div>
</div>

3 Comments

<div class="{{obj.first}}">{{obj.first}}</div>// added for your reference inbetween div {{obj.first}}
It is checkbox group, selected only one checkbox at a time
if you want to multiple just change ng-model name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.