i have a group of Radio buttons and i need to check if one has been clicked if not then throw an erorr how can i validate the below with Jquery?
<legend>Follow Opening Script?</legend>
<p>
<strong><asp:RadioButton GroupName="OpeningScript" CssClass="inline-radio" ID="rdoOpeningScriptYes" runat="server" Text="Yes" TextAlign="Right" /></strong>
<strong><asp:RadioButton GroupName="OpeningScript" CssClass="inline-radio" ID="rdoOpeningScriptNo" runat="server" Text="No" TextAlign="Right" /></strong>
</p>
Here a jsfiddle example for you: http://jsfiddle.net/xYLxX/
Register event on document ready:
$('input[name="OpeningScript"]').click(function () {
alert($(this).val());
});
Change the index to get the status of particular item:
$("input[name*=OpeningScript]")[0].checked
To get the text try:
$("input[name*=OpeningScript]:checked + label").text();
Add a button
to your HTML:
<input type="button" id="check" value="check" />
And write a function for its click
to check:
$(function () {
$('#check').on('click', function () {
if (! $('[name="OpeningScript"]:checked').length) {
alert('Please choose an option');
}
});
});