Looping Through Dynamically Generated Checkboxes to Get Values

Looping through dynamically generated checkboxes to get values

Thanks to @CBroe for getting there first, that worked for me.

var categories = '';
var category = document.getElementsByClassName("product_category");
var i;
for(i=0; i<category.length; i++){
if(category[i].checked == true){
var category_value = category[i].value;
categories += category_value+',';
}
}

jQuery Loop Through dynamically Generated Checkboxes And Default Check Them All

Give all the checkboxes a common class, and use that class when setting the property.

$(function() {
$(".selectall").prop("checked", true);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" value="2006" id="SelectAll_2006" class="selectall"> 2006<br>
<input type="checkbox" value="2007" id="SelectAll_2007" class="selectall"> 2007<br>
<input type="checkbox" value="2008" id="SelectAll_2008" class="selectall"> 2008<br>
<input type="checkbox" value="2009" id="SelectAll_2009" class="selectall"> 2009<br>

Dynamically loop through checkboxes and get their value and isChecked

     view.$el.find('div.checkboxes input').change(function (event) {

var id = $(event.target).attr('data-id');

if ($(event.target).prop('checked')) {

resultSetParameters.get('filter').coachProperties.push(id);

resultSetParameters.trigger('change');

} else {

var index = resultSetParameters.get('filter').coachProperties.indexOf(id);

if (index > -1) {

resultSetParameters.get('filter').coachProperties.splice(index, 1);

resultSetParameters.trigger('change');

}

}

});

How to get dynamically generated check box values

Use the :checked selector

jQuery('.A:checked')

You can then loop over the elements to get all their values.

How to get value of dynamically generated checkboxes if the checkbox is true in Angularjs

go through angular checkbox

use ng-true-value and ng-true-value

<ul>
<li ng-repeat="screen in screenMap">
<input type="text" ng-model="screen.scrn_name" />
<input type="hidden" value="{{screen.scrn_id}}"/>
<input type="checkbox" name="vehicle" ng-model="screen.write" ng-true-value="true" ng-false-value="false">
<input type="checkbox" name="vehicle" ng-model="screen.read" ng-true-value="true" ng-false-value="false"><br>
</li>
</ul>
<input type="button" value="APPLY" ng-click="apply()"/>


$scope.apply = function () {
console.log($scope.screenMap);//[{..,read:true,write:false},...]
}


Related Topics



Leave a reply



Submit