theonlychase
7/17/2017 - 3:58 PM

Copy id of a div and pass it in to the value of a checkbox, then saves the values.

Copy id of a div and pass it in to the value of a checkbox, then saves the values.

// HTML

<tbody>
        <tr id="row_10358" role="row" class="odd">
            <td>Walid</td>
            <td class="sorting_1">Abdul-Wahab</td>

// Button
<input type="button" id="button_id" name="save_value" value="Save" />

// jQuery and JavaScript

$('thead tr').append('<th>Select</th>');
$('tbody tr').append(function(index) {
return '<td id="'+index+'"></td>';
});

$("tbody tr").each(function(index, value) {
	var id = $(this).attr('id');
  $(this.children[2]).append('<input type="checkbox" value="'+id+'">');
});


$(function(){
      $('#button_id').click(function(){
        var val = [];
        $(':checkbox:checked').each(function(i){
          val[i] = $(this).val();
        });
        alert(val);
      });
    });