Reputation: 46222
I have the following radion button in VB.NET
<asp:RadioButtonList ID="rbedit" runat="server" RepeatDirection="horizontal" >
<asp:ListItem Value="1" >Yes</asp:ListItem>
<asp:ListItem Value="0" >No</asp:ListItem>
</asp:RadioButtonList></td>
I need to figure what button the user clicked on and then set a variable with that value. How would I go about doing this?
Upvotes: 1
Views: 1537
Reputation: 772
You can use rbedit.SelectedIndex to get which button user clicked and then set the variable accordingly.
If you want to get it client side then use following code :
function getRadVal(radlist)
{
if (document.forms['Form1'].elements[radlist])
{ var radGrp = document.forms['Form1'].elements[radlist];
var radGrpValue = '0';
for (var i = 0; i < radGrp.length; i++)
if (radGrp[i].checked) {
radGrpValue = radGrp[i].value;
break;
}
return radGrpValue;
}
else
return '';
}
to call this use : // Get Value of RadioButtonList
var myValue=getRadVal('rbedit');
Upvotes: 3