2

Once a checkbox is ticked on a form, I am calling a function that performs certain checks and enables a previously disabled button.

My js code has the following:

$('#default_address').change ->
    id = $('#default_address').val()
    if(this.checked)
      $.ajax({
        url: '/shipments/' + id + '/get_address',
        dataType: "JSON",
        success: (data) ->
          $('#billing_address_address_line1').val(data[0])
          $('#billing_address_address_line2').val(data[1])
          $('#billing_address_phone_number').val(data[2])
      }).done
      checkPlaceOrderValidity()

The checkPlaceOrderValidity() method is as shown below:

@checkPlaceOrderValidity = ->
  // some code
  else
    place_order_btn.attr 'disabled', false
    place_order_btn.removeClass 'disabled'

If I add an alert just before calling the checkPlaceOrderValidity() method, it works fine(which I found really strange). I m unable to find the cause even after debugging my code.

0

1 Answer 1

2

Try this,

$.ajax({
url: '/shipments/' + id + '/get_address',
        dataType: "JSON",
        success: (data) - >
        $('#billing_address_address_line1').val(data[0])
        $('#billing_address_address_line2').val(data[1])
        $('#billing_address_phone_number').val(data[2])
}).done(checkPlaceOrderValidity);
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.