Search code examples
jqueryradio-buttonsweetalert2

If radio is checked then show a message action


I have a input radio in HTML

<input class="payment_processor_gocardless crm-form-radio" value="5" type="radio" id="QFID_5_payment_processor_id" name="payment_processor_id">

Normally the radio is not selected. What I would like to do is, whenever I click that radio, I want a message to show via sweetalert. Here's my code:

$('input[name=payment_processor_id]”]’).click(function()  {
    if (($("input[name=payment_processor_id]").attr("value")=="5") ) {  
          Swal.fire({
sweetalert message goes here
        });
  }
});

Sweetalert is functional in other areas, so that's not my concern. I cant trigger it when selected the radio button. Any help would be appreciated. Thanks


Solution

  • You were doing some semantics error, have done modifications in your code.

    $('input[name="payment_processor_id"]').click(function()  {
        if (($('input[name="payment_processor_id"]').attr("value")=="5") ) {  
              Swal.fire({
                  sweetalert message goes here
            });
      }
    });