I'm trying to get the data from the td cells when the checkbox is checked in the same row in an object to pass it to other page but I get /n in return..
productOrder.ejs
<table id="review-products">
<thead>
<tr>
<th ></th>
<th>Product Name</th>
<th>Price </th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<% products.forEach((products) => { %>
<tr id="order-item-510" class="tst-orderItemRow">
<td>
<input type="checkbox" value="<%= products.productId %>" id="check" >
</td>
<td class="name" >
<%= products.productName %>
</td>
<td class="currency" >
<%= products.price %>
</td>
<td class="quant">
<input type="text" class="foo" value="" >
</td>
</tr>
<% }) %>
</tbody>
</table>
<button id="save" name="button">Save</button>
My ajax code:
$("#review-products input[type=checkbox]:checked").each(function() {
var row = $(this).closest("tr");
var message0 = row.find('#check').val();
var message1 = row.find('.name').text();
var message2 = row.find('.currency').text();
var message3 = row.find(".foo").val();
var result = {
check: message0,
name: message1,
p: message2,
q: message3,
total: message2 * message3
}
console.log(result);
});
and in the console I got this: {check: "1", name: "↵ ball↵ ", p: "↵ 10↵ ", q: "3", total: 30}