<script>
    jQuery(document).on('click', '#{{tableid}} tr', function(){
        var fieldText = "";
        var rows = jQuery('#{{tableid}}').find('tr[id]');

        var rowIds = [];
        for(var i=0; i < rows.length; i++){
            var elem = jQuery(rows[i]).children(':nth-child({{tablepos}})');

            if(jQuery(elem).text() != ''){
                rowIds.push(i);
            }
        }

        for(var j=0; j < rowIds.length; j++){
            if(j != 0){
                fieldText += '\n';
            }
            var textThisCell = jQuery(rows[rowIds[j]]).children(':first-child').text().trim().replace(/\n\n/g, '\n');
            fieldText += textThisCell;
        }
        jQuery('[data-formid="{{formid}}"]').find('textarea').val(fieldText);
    });
</script>