4
$("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.

j08691
  • 197,815
  • 30
  • 248
  • 265
Bishal Paudel
  • 1,777
  • 2
  • 20
  • 27

4 Answers4

11

jQuery objects do not have a checked property. Replace

current_checkbox.checked

with

current_checkbox.prop('checked')

http://api.jquery.com/prop

Blazemonger
  • 86,267
  • 25
  • 136
  • 177
5

You are using current_checkbox.checked, checkbox has not any 'checked' properties, but you can use $('#id').is(':checked')

Kerem Kulak
  • 51
  • 1
  • 2
2

You're using a jQuery element, not a DOM element. Use:

if(current_checkbox.prop("checked")) {

} //just for Steve <3
Steve
  • 8,469
  • 6
  • 39
  • 53
Sterling Archer
  • 21,348
  • 17
  • 79
  • 113
1

current_row.find("input[name=checkbox]")

I'm fairly sure this returns a jQuery object, not the underlying checkbox element.

if(current_checkbox[0].checked)

Should work.

Niet the Dark Absol
  • 311,322
  • 76
  • 447
  • 566