Search code examples
jqueryradio-buttononchange

How to apply on change event on radio button using jquery


HTML:

<div class="radio-list  ">
     <label class="radio-inline">
     <span class=""><input type="radio" name="data[Customer][service_type]" id="service_type" value="new" checked=""></span> NEW INSTALLATION </label>
     <label class="radio-inline">
     <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="repair"></span> SERVICE REPAIR </label>
  <label class="radio-inline">
  <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="cancel"></span> CANCEL SERVICE </label>
  <label class="radio-inline">
  <span class="checked"><input type="radio" name="data[Customer][service_type]" id="service_type" value="other"></span> OTHER SERVICE </label>
</div>

How to apply on change event on <input type="radio" name="data[Customer][service_type]" id="service_type" value="cancel"> ?


Solution

  • $(function(){
    
        $("input:radio[name='data[Customer][service_type]']").change(function(){
            var _val = $(this).val();
            console.log(_val);
        });
    
    });
    

    .change is the event which you need to trigger.

    See it here.