Monday 21 August 2017

Check if a RadioButtonList is selected (checked) or not using JavaScript in ASP.Net

Check if a RadioButtonList is selected (checked) or not using JavaScript in ASP.Net

Description:

In this example we explain that how to check  if RadioButtonList  is checked or not using JavaScript.or how to check if RadioButtonList  is selected or not selected using JavaScript.

Code:

<script type="text/javascript">
        function checkGameisSelectOrNot() {
            var rb = document.getElementById("<%=gameRadioButtonList.ClientID%>");
            var radio = rb.getElementsByTagName("input");
            var isChecked = false;
            for (var i = 0; i < radio.length; i++) {
                if (radio[i].checked) {
                    isChecked = true;
                    break;
                }
            }
            if (!isChecked) {
                alert("Please select any Game to Move Further!");
            }

            return isChecked;
        }
    </script>
    <title>Check if a RadioButtonList is selected (checked) or not using JavaScript in ASP.Net
    </title>
<body>
    <form>
    <asp:radiobuttonlist id="gameRadioButtonList" runat="server">
    <asp:ListItem Text="Cricket" Value="1"></asp:ListItem>
    <asp:ListItem Text="FootBall" Value="2"></asp:ListItem>
    <asp:ListItem Text="Tennis" Value="3"></asp:ListItem>
</asp:radiobuttonlist>
    <br />
    <asp:button id="btnSubmit" runat="server" text="Check" onclientclick="return checkGameisSelectOrNot()" />
    </form>
</body>


0 comments:

Post a Comment