Radio button checked event handling

tarique picture tarique · Apr 28, 2010 · Viewed 103.7k times · Source

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?

Answer

Sarfraz picture Sarfraz · Apr 28, 2010

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').