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> 
Code Ratchet
  • 5,758
  • 18
  • 77
  • 141

3 Answers3

0

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

Michal B.
  • 5,676
  • 6
  • 42
  • 70
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();
Ren
  • 1,111
  • 5
  • 15
  • 24
Nag
  • 1
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');
        }
    });
});