Reputation: 23
I want a javascript or jquery function that searches in a html table and if no radio is selected notify the user.I only have table id and don't know radio id(s).
Upvotes: 0
Views: 272
Reputation: 74420
You can use is()
which returns a boolean:
if (!$('table :radio').is(':checked')) {
alert('No Radio Button Selected');
}
If at least one radio button is checked, this won't fired alert()
Upvotes: 0
Reputation: 57105
In the code you can replace table
with #tableID
so that code only runs for that table
$(document).ready(function () {
if ($('table input[type=radio]:checked').length < 1) {
alert('No Radio Button Selected');
}
});
if you want to notify on table
click
$('table').click(function () {
if ($('table input[type=radio]:checked').length < 1) {
alert('No Radio Button Selected');
}
});
Upvotes: 3
Reputation: 1122
$('#table input:radio:checked') will give the radios checked inside table with id `#table`
Upvotes: 0