js is great in some ways but quite often simplest tasks become a nightmare. In my case, I display the order numbers and all other order data on the orders list screen of my app, no problems. All I want to do is to get the orderno of the order that I select on the orders list screen then click the status update button to update the order status. However, no matter what I try, I can’t get the selected order’s number. This should be a very simple task but it has turned into a nightmare. In the js code I provided, I am using jQuery to get the current row and then find the orderno element in the current row. But it is not working. I have checked out other similar questions/answers but found no answer to my problem. Any help will be appreciated.
<script type="text/javascript">
function upd_ordrstatus() {
for (var i=0; i < order_selector.length; i++){
if (order_selector[i].checked) {
$(document).ready(function(){
$("#updstat_btn").click(function(){
var currentRow=$(this).closest("tr"); // get the current row
var orderno = currentRow.find(".orderno").text(); // get the orderno in the current row.
console.log("orderno: ", orderno);
})
})
}
}
}
<tbody>
<%
if(ordersdata.length) {
for(var i = 0; i< ordersdata.length; i++) {%>
<div class="orderdata" id="orderdata">
<tr>
<td><input type="checkbox" class="order_selector" id="order_selector"></td>
<td class="orderno" id="orderno" style="width:60px"><%= ordersdata[i].orderno %></td>
<td class="orderdate" id="orderdate" style="width:60px"><%= ordersdata[i].order_date %></td>
<td class="orderstat" id="ordrstat" style="width:75px"><%= ordersdata[i].order_status %></td>
<td class="sku" id ="sku" name="sku" style="width:125px"><%=
</tr>
</div>
<%}
} else {%>
<tr>
<td colspan="4">Siparis listesi boş!</td>
</tr>
<%}
%>
</tbody>
</table>
<button type="button" class="updstat_btn" id="updstat_btn" name="updstat_btn" onclick="upd_ordrstatus()">Seçilenlerin Statüsünü Güncelle</button>
1