Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery checkbox.checked always returns false

$("tbody input[name='rooms_to_book']").on('change',function(){
    var current_row = $(this).closest("tr");
    var current_checkbox = current_row.find("input[name=checkbox]");
    if(current_checkbox.checked) {
        var price_per_night = parseFloat(current_row.find("td[name=price]").text().replace('$',''));
        var rooms_to_book = parseInt(current_row.find("input[name=rooms_to_book]").val());
        rooms_to_book = rooms_to_book ? rooms_to_book : 0;
        total_price = price_per_night * rooms_to_book;
    }else{
        total_price = 0;
    }
    current_row.find("td[name=total_price]").text('$'+ total_price);
});

The current_checkbox.checked always returns false, the html is correct.

like image 458
Bishal Paudel Avatar asked Dec 02 '22 17:12

Bishal Paudel


1 Answers

jQuery objects do not have a checked property. Replace

current_checkbox.checked

with

current_checkbox.prop('checked')

http://api.jquery.com/prop

like image 187
Blazemonger Avatar answered Dec 10 '22 12:12

Blazemonger