How to check two radio buttons with the same groupname

Go To StackoverFlow.com

0

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>&nbsp;&nbsp;
    <strong><asp:RadioButton GroupName="OpeningScript" CssClass="inline-radio" ID="rdoOpeningScriptNo" runat="server" Text="No" TextAlign="Right" /></strong>
</p> 
2012-04-04 07:27
by Code Ratchet
You should really post the actual HTML, not the asp tags - ThiefMaster 2012-04-04 07:29
http://stackoverflow.com/questions/277589/validation-of-radio-button-group-using-jquery-validation-plugin will this help - TRR 2012-04-04 07:30


0

Here a jsfiddle example for you: http://jsfiddle.net/xYLxX/

2012-04-04 07:39
by Michal B.


0

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();
2013-05-20 09:20
by Nag


0

Working FIDDLE Demo

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');
        }
    });
});
2013-05-20 09:26
by NoName
Ads