Search code examples
jqueryradio-buttonchecked

Radio button checked event handling


In my application, I need a radio group, in which whenever a radio-button is checked, an alert occur so that I can post it's value to ajax post with jQuery.

Can you help me please how i can do it in jQuery?


Solution

  • Try something like this:

    $(function(){
      $('input[type="radio"]').click(function(){
        if ($(this).is(':checked'))
        {
          alert($(this).val());
        }
      });
    });
    

    If you give your radio buttons a class then you can replace the code $('input[type="radio"]') with $('.someclass').