views:

197

answers:

3

Hello

In my application i need a radio group, in which whenever a button is checked, an alert occur so that i can post its value to ajax post in jquery.

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

+6  A: 

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

Sarfraz
You can change the value of a radio WITHOUT clicking it...
David Murdoch
@David Murdoch: yeah that's right, you could use `change` though.
Sarfraz
Thanks Sarfraz. It works
TIT
@TIT: You are welcome....
Sarfraz
+2  A: 
$('#radioId').click(function() {
        if ($(this).is(':checked')) {
      // put your code here and your alert
   }
}
Amr ElGarhy
He is talking about radio buttons. You can also change the value of a radio WITHOUT clicking it...
David Murdoch
A: 
$("input[type=radio]").change(function(){
    alert( $("input[type=radio][name="+ this.name + "]").val() );
});
David Murdoch
why the down vote?
David Murdoch