air
air

Reputation: 6264

getting value of Radio Button with jquery

i have defined radio buttons as bellow

<tr>
   <th height="35" scope="row">
       <div align="left">Response for Instruction</div>
   </th>
   <th scope="row"><input name="a"  type="radio" value="Excellent" /></th>
   <th scope="row"><input name="a"  type="radio" value="Good" /></th>
   <th scope="row"><input name="a"  type="radio" value="Poor" /></th>
   <th scope="row"><input name="a"  type="radio" value="Needs Improvement " /></th>
</tr>

$(document).ready(function() {
    var a = $('#a').attr('value');
    alert(a);
}

but its showing undefined.

Thanks

Upvotes: 0

Views: 1546

Answers (5)

Karthick V
Karthick V

Reputation: 1289

Try This

 $("input:radio[name=a]").click(function() {
    var value = $(this).val();
    console.log(value);
  });

Upvotes: 2

user739881
user739881

Reputation:

Probably this will help...

$("input[@name=a]:checked").val();

Upvotes: 0

Tats_innit
Tats_innit

Reputation: 34107

Working demo http://jsfiddle.net/qh6Et/3/

code

$("input[type='radio']").click(function(){
    var a     = $(this).attr('value');
    alert(a);
});
​

Upvotes: 1

C. Leung
C. Leung

Reputation: 6318

it should be

var a = $('input[name="a"]').attr('value');

Upvotes: 0

tibo
tibo

Reputation: 5474

$("input:radio[name=a]:checked").val()

Upvotes: 5

Related Questions