I have a table where the user can add rows. I would like to place the number of rows in another field. How would I go about doing this? So I would like the number of rows in the New Product table to be placed into the Total Batches Field:
Thanks!
I have a table where the user can add rows. I would like to place the number of rows in another field. How would I go about doing this? So I would like the number of rows in the New Product table to be placed into the Total Batches Field:
Thanks!
You can use custom javascript for this. In the example, the table has the css class name "mytable" and the field containing the row count has the css class name "myrows"
$(document).ready(function() {
rowcount();
$('.mytable').on('click', '.form-del-field', function () {
rowcount();
});
$('.mytable').on('click', '.cf-table-add-row', function () {
rowcount();
});
function rowcount() {
$('.myrows input').val($('.mytable tr').length-1);
}
});
I used the code given here to build a table (tablejq). When adding rows, the total-field (totalInTable) gets updated perfectly, but when a row is deleted using the 'x', the total-field remains the same. Can someone please help. Thank you.
My code is:
$(document).ready(function() {
rowcount();
$('.tablejq').on('click', '.form-del-field', function () {
rowcount();
});
$('.tablejq').on('click', '.cf-table-add-row', function () {
rowcount();
});
function rowcount() {
$('.totalInTable input').val($('.tablejq tr').length-1);
}
});