Completing my code! - Copying a record between two objects

Completing my code! - Copying a record between two objects

Objective:

I have a table which has a column of check boxes in the first column. Then I have a button which applies an effect to the selected rows in that table. The button should copy the selected row, to another object.

What the Code Below Currently Does:

The code below applies the check boxes to the table, and places the button on the page.

What is Missing from the Code Below?

The action of the button, which copies the selected records to another table (object).

The Code:

  1. // ------ Function to Add to Checkboxes ------

  2. var addCheckboxes = function(view) {
  3.    
  4.   // add the checkbox to to the header to select/unselect all
  5.   $('#' + view.key + '.kn-table thead tr').prepend('<th><input type="checkbox"></th>');
  6.   $('#' + view.key + '.kn-table thead input').change(function() {
  7.      
  8.     $('.' + view.key + '.kn-table tbody tr input').each(function() {
  9.       $(this).attr('checked', $('#' + view.key + '.kn-table thead input').attr('checked') != undefined);
  10.     });
  11.   });
  12.    
  13.   // add a checkbox to each row in the table body
  14.   $('#' + view.key + '.kn-table tbody tr').each(function() {
  15.     $(this).prepend('<td><input type="checkbox"></td>');
  16.   });
  17. }


  18. // ------ Function to Add to Cart on Quotes 1 Interface ------


  19. $(document).on('knack-view-render.view_54', function (event, view) {
  20.     // Adds button and calls checkbox function to view
  21.     $('<button id="update"">Add to Cart</button>').insertAfter('.kn-filters-nav');   
  22.     addCheckboxes(view);
  23.    
  24.   $('#update').click(function () {
  25.     console.log(view.key);
  26.     var checked = $('#' + view.key + ' tbody input[type=checkbox]:checked');
  27.      
  28.     calls = checked.length;
  29.     success = 0;
  30.      
  31.     Knack.showSpinner();
  32.       
  33.     checked.each(function() {
  34.          
  35.       var id = $(this).closest('tr').attr('id'); // record id
  36.        
  37.       var data = {
  38.         field_246: Knack.getUserAttributes().id 
  39.       };
  40.          
  41.         $.ajax({
  42.             url: 'https://api.knackhq.com/v1/objects/object_1/records/' + id,
  43.             type: 'PUT',
  44.             headers: {'X-Knack-Application-ID': 'XXXXXXXXXXXXXX': 'XXXXXXXXXXXXXXX'},
  45.             data: data,
  46.             success: function (response) { // each time an update completes, our success variable increases by 1
  47.                 success+=1;
  48.                 if(success==calls) { // if the number of success calls = the number of checked boxes...
  49.                     Knack.hideSpinner();
  50.                     alert('Quotes added to your cart.');
  51.             }
  52.          }
  53.       });
  54.     });
  55.   })
  56. });

Database is built on a platform called Knack. It's 100% online. Appreciate any help!! I'm not an expert here, and am working off examples.

Thanks,
Robert