jQuery code not working

My jQuery code is not working. Every seat is a checkbox. I am trying to disable those seats that are booked by other users.

      type: 'GET',
      url: "{!!URL::to('bookedTickets')!!}",
        for(var i=0; i<data.length; i++)
          if($(":checkbox").val() == data[i].SeatNumber)


JSON Data received at ajax

johnathansantos replied 1 year ago

val() return the value of the input

prop('checked') return or if the input is checked

<input value='aaa' checked type='checkbox' id='a' class='checkbox'/>
<input value='bbb' type='checkbox' id='b' class='checkbox'/>
$(':checkbox') // list all checkbox 
$(':checkbox').val() // 'aaa'  - value of the first element 
$(':checkbox').eq(0).val() // 'aaa'

$(':checkbox').eq(0).prop('checked') //true
$(':checkbox').eq(1).prop('checked') //fase
$('input.checkbox:checked').prop('checked') //true
$('.checkbox:checked')[0].checked //true

$('#a')[0].checked //true
$('#a').prop('checked') //true

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us