In this post Asp.Net jQuery get
List of checked RadioButtons in the Page, we shall see on how to get a
comma separated list of id’s of all the checked radio buttons in a page
We can use the following script to get
the radio button list in a Page
var
selectedIDs = '';
var
selectedValues = '';
$("input[type=radio][checked]").each(function() {
if (selectedIDs.length == 0) {
selectedIDs = $(this).attr('id');
selectedValues = $('label[for=' + this.id + ']').html();
}
else {
selectedIDs += ", " + $(this).attr('id');
selectedValues += ", " + $('label[for=' + this.id
+ ']').html();
}
});
alert('Selected
IDs: ' + selectedIDs);
alert('Selected
Values: ' + selectedValues);
On click of a button uses the following script.
// Loop through - Get List of Selected RadioButtons in the Page
$('#cmdGetSelectedList').click(function(event) {
event.preventDefault();
var
selectedIDs = '';
var
selectedValues = '';
$("input[type=radio][checked]").each(function() {
if
(selectedIDs.length == 0) {
selectedIDs = $(this).attr('id');
selectedValues = $('label[for=' + this.id
+ ']').html();
}
else {
selectedIDs += ", " + $(this).attr('id');
selectedValues += ", " + $('label[for='
+ this.id + ']').html();
}
});
alert('Selected
IDs: ' + selectedIDs);
alert('Selected
Values: ' + selectedValues);
});
To see a full example using jQuery and Radio Buttons refer to the post Asp.Net jQuery Radio Button Tutorial
To see a full example using jQuery and Radio Buttons refer to the post Asp.Net jQuery Radio Button Tutorial
Related Posts
No comments:
Post a Comment