Reputation: 10765
I have a table in which last column of each row have a radio button and hidden filed .
I have set value to each hidden field now i want to capture the hidden field value of which radio button is selected.
AS i have same name for all radio buttons in that table so user can select only one radio button at once.
here is my jquery code to check whether radio button is selected or not .
$('.btnNext').on('click', function() {
alert('clicked');
if (!$('#TblPayFrequencyInfo :radio').is(':checked')) {
alert('No radio selected ');
}
else
{
alert('radio selected ');
}
});
Now my task is to get the hidden field value of row in which radio button is selected.
Upvotes: 0
Views: 1166
Reputation: 2988
try this
$('.btnNext').on('click', function() {
if (!$('#TblPayFrequencyInfo :radio').is(':checked')) {
alert('No radio selected ');
}
else
{
var row = $("input[type=radio]:checked").parent();
console.log(row);
console.log(row.find("#_PayFrequencyId_").val());
alert('radio selected ');
}
});
Upvotes: 0
Reputation: 20418
Try this
$('.btnNext').on('click', function() {
alert('clicked');
if (!$('#TblPayFrequencyInfo :radio').is(':checked')) {
alert('No radio selected ');
}
else
{
alert('radio selected ');alert($('#TblPayFrequencyInfo :radio:checked').next().val());
}
});
Upvotes: 0
Reputation: 388316
The hidden field is the next sibling of the selected radio, so you can use .next()
$('.btnNext').on('click', function () {
var $selected = $('#TblPayFrequencyInfo input:radio:checked')
if ($selected.length) {
var hidden = $selected.next().val()
alert('radio selected ' + hidden);
} else {
alert('No radio selected ');
}
});
Demo: Fiddle
Upvotes: 2