How to check radiobutton list values using javascript? [Resolved]

Posted by Hariinakoti under JavaScript on 10/13/2012 | Points: 10 | Views : 5526 | Status : [Member] | Replies : 2
Hi,
I want to check radiobutton list values using javascript.I have 5 list items in radiobutton list.If we check first item that value is true remaining all are false.and second item we select that is only true remaining all are false .I want output like that .Anybody can give good solution to me.i checked already in google there is so many solutions for 2list items only i tried like that.But it is not working.

Thanks & Regards
Hari



Responses

Posted by: Self-Innovator on: 10/15/2012 [Member] Bronze | Points: 50

Up
0
Down

Resolved
For Multiple Childs if you have in your control
then try this in if condition of Javascript function
for(k=0;k<Gender.cells.length;k++)

{
if(Gender.cells[k].firstChild.checked)
{
flag=1;
break;
}


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-Innovator on: 10/15/2012 [Member] Bronze | Points: 25

Up
0
Down
hi try this to validate
Page Design
.aspx Code
<table>

<tr>
<td><asp:Label ID="lblGender" runat="server" Text="Gender"></asp:Label></td>
<td style="width: 197px">
<asp:RadioButtonList ID="rblGender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
</table>

JavaScript Function
<script language="javascript" type="text/javascript">

function Validate()
{
var Gender=document.getElementById("rblGender");
var flag=0;
for(i=0;i<Gender.cells.length;i++)
{
if(Gender.cells.firstChild.checked)
{
flag=1;
break;
}
}
if(flag==0)
{
alert("Please choose gender");
return false;
}
}
</script>

Code Behind
Page_load()

{
btnSubmit.Attributes.Add("onClick", "return Validate()");
}


Join Hands Change lives
Thanks & Regards
Straight Edge Society

Hariinakoti, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response