prashanth
prashanth

Reputation: 445

jquery radio button checked attribute?

<input type="radio" value="G;-;P063P081719;-;84.063" name="awardDetail"/>
<input type="radio" value="G;-;P063P091719;-;84.063" name="awardDetail"/>
<input type="radio" value="G;-;P063Q081719;-;84.063" name="awardDetail"/>

I am not selecting a default checket attribute checked="checked". When I am selecting a radio button, I am making an Ajax call based.

$('input[name=awardDetail]:radio').click(function(){
    var awardinfo = $('input[name=awardDetail]:checked').val();

and sending this awardinfo to the Ajax function and the returned data from server to display in the DIV.

However, my radio button is checked to previous radio button rather than the current selected radio button.

How do I set the checked attribute for this radio button passing the selected index dynamically.

The radio button values group is dynamically generated from backend.

Upvotes: 0

Views: 3405

Answers (1)

Russ Cam
Russ Cam

Reputation: 125488

You can reference the clicked radio button inside the handler using keyword this (or using event.target). For example

$('input[name=awardDetail]:radio').click(function(){ 
    var awardinfo = $(this).val();
    // other stuff here for ajax call, etc
}

or

$('input[name=awardDetail]:radio').click(function(event){ 
    var awardinfo = $(event.target).val();
    // other stuff here for ajax call, etc
}

Upvotes: 2

Related Questions