Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
<tr>
    <td>
        <asp:Label ID="Label2" runat="server" Text="SEX"></td>
    <td style="width: 203px">
        <asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
        <asp:ListItem>MALE
        <asp:ListItem>FEMALE
        
    </td>
</tr>


i want to validate a RadioButtonList using javascripts for the above details... can any one able to assist me....
Posted
Updated 14-Dec-11 22:34pm
v2
Comments
RaviRanjanKr 15-Dec-11 4:35am    
[Edited]Code is wrapped in "pre" tag[/Edited]
Member 10433454 3-Jan-14 3:31am    
Hello..
I have two Radio Btn:
<input type="radio" name="selectedTool" value="name" id="rbnName" checked="checked">Name<br>
<input type="radio" name="selectedTool" value="age" id="rbnAge">Age

this is in client side and my question is I want to use same radio btn in server side,
so when I checked Name in Client side then I need to same Name checked in Server side as well....
It means changes in both places similary in client side or in server side....

JavaScript
<script language="javascript" type="text/javascript">
    function validate()
    {     
    if (document.getElementById("RadioButtonList1").checked==false)
    {
    var answer = confirm ("Please confirm selection...")
    if (answer)
    return true;
    else
    return false;
    }         
    return true;
    }
    </script>



Refer this....
validation of radiobutton using javascript[^]
 
Share this answer
 
v4
Comments
Gopinath1005 15-Dec-11 4:31am    
its not working ji....
Neha Thanka 15-Dec-11 4:59am    
Try this link....
http://www.codeproject.com/Questions/207523/display-alert-when-radio-button-is-not-selected.aspx
 
Share this answer
 
Comments
Gopinath1005 15-Dec-11 6:20am    
sorry boss..i need only in java scripts....
Hi,
Try this one,
C#
function validate()
{
    var selected = $('#<%=RadioButtonList1.ClientID %> input:radio:checked').length;
if( selected>0){alert("valid");}
else{alert("Invalid");}
}
 
Share this answer
 
Comments
Gopinath1005 15-Dec-11 6:20am    
sorry boss..i need only in java scripts....
C#
<asp:RadioButtonList ID="RadioButtonList1" runat="server" RepeatDirection="Horizontal">
       <asp:ListItem>MALE</asp:ListItem>
       <asp:ListItem>FEMALE</asp:ListItem> </asp:RadioButtonList>
       <asp:requiredfieldvalidator id="RequiredFieldValidator1" runat="server"
           ControlToValidate="RadioButtonList1" ErrorMessage="Please Select"></asp:requiredfieldvalidator>


this is enough just add a requried filed validator give the radiobuttonlist list id as control to validate in the required field validator like the example above this would do validation both client side and server side it generates the javascript for client side
 
Share this answer
 
v3
HTML
<script language="javascript" type="text/javascript">
    function validate()
    {    
var check= document.getElementByid("RadioButton").checked;
    if (check==false)
    {
   alert("check  item")
   
    return false;
    }

   
   
    return true;
    }
    </script;</script>
 
Share this answer
 
v2
Comments
Gopinath1005 15-Dec-11 8:09am    
not working ji..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900