0

I have tried using the following code for checking radiobutton selection but it shows alert even after selection

    <script type="text/javascript">
    function validate() 
    {
    if (!document.getElementById('<%= Radiobuttonlist1.ClientID %>').checked) 
         {
                    alert("Please select type");
                    return false;
         }
    }
    </script>

        <asp:radiobuttonlist ID="Radiobuttonlist1" runat="server" 
                    RepeatDirection="Horizontal" >
                <asp:ListItem>Text</asp:ListItem>
                <asp:ListItem>Number</asp:ListItem>
                <asp:ListItem>Character</asp:ListItem>
                </asp:radiobuttonlist>

        <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return validate();" onclick="Button1_Click"/>
  • possible duplicate of http://stackoverflow.com/questions/1541160/how-do-you-get-the-checked-value-of-aspradiobutton-with-jquery – Veena Mar 10 '15 at 06:28
  • 1
    When you call this function?? – User2012384 Mar 10 '15 at 06:29
  • Can you check after extracting condition in some variable. Like : var args =document.getElementById('<%= Radiobuttonlist1.ClientID %>').checked; if(!args){ alert("Please select type"); return false;} – Arpit Aggarwal Mar 10 '15 at 06:31
  • @Arpit, thats asp.net code. You can't get the element by using that Id as it will be populated dynamically by .Net –  Mar 10 '15 at 07:13
  • I am asking to check after making modifications in the function under – Arpit Aggarwal Mar 10 '15 at 07:45
  • Problem here is the Id's are getting created at runtime. So its very difficult to get at the Id value. –  Mar 10 '15 at 08:09

0 Answers0