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
Generate a Weighted Random Number
Javascript Odd and Even Separation in an Array of Numbers
Fullcalendar - Change View for Mobile Devices
How to Hide Blinking Cursor in Input Text
Check If Value Select2 Is Null
Regular Expression Which Matches a Pattern, or Is an Empty String
React-Select:Get Default Value in React-Select
Angular 2 Not Updating Until Any Object Is Clicked
Angular 6 Store Data from Json Array Inside Json
How to Handle Multiple Submit Buttons in a Form Using Angular Js
How to Push Value Pair into Object Using Method
How to Align Text Input Correctly in React Native
Calculate the Bounding Box'S X, Y, Height and Width of a Rotated Element Via JavaScript
Detect Click into Iframe Using JavaScript
Text Input Allow Only Integer Input in Angularjs
Filereader Onload With Result and Parameter