Hi guys,
I'm planning to create a checklist using javascript code to create checkbox in a table (which will be my checklist). The problem is that I do not know how to javascript program and was wondering if anyone could tell me how to make my app record when an item is checked. I also would like to know if there is a way to make checkbox go from left side to the right side.
Here is the code I used to make the checkbox appear in a table:
// function that adds checkboxes var addCheckboxes = function(view) {// add the checkbox to to the header to select/unselect all
$(’#’ + view.key + ‘.kn-table thead tr’).prepend(’<th><input type=“checkbox”></th>’);
$(’#’ + view.key + ‘.kn-table thead input’).change(function() {$('.' + view.key + '.kn-table tbody tr input').each(function() { $(this).attr('checked', $('#' + view.key + '.kn-table thead input').attr('checked') != undefined); });
});
// add a checkbox to each row in the table body
$(’#’ + view.key + ‘.kn-table tbody tr’).each(function() {
$(this).prepend(’<td><input type=“checkbox”></td>’);
});
}// add checkboxes to a specific table view (view_289). Change “view_289” to your view key
$(document).on(‘knack-view-render.view_289’, function (event, view) {
addCheckboxes(view);
});// Cycle through selected checkboxes. Use this in any code that needs to get the checked IDs
$(’#view_289 tbody input[type=checkbox]:checked’).each(function() {
// add code here to get record id or row value
var id = $(this).closest(‘tr’).attr(‘id’); // record id
});