Click here to Skip to main content
15,917,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have a radiobuttonlist in my web application I have an event onclick for this it works fine in IE but not in some other browsers. The sample code is as follows
XML
<asp:RadioButtonList ID="rbgThreadStatus" runat="server" RepeatDirection="Horizontal"
                                                OnSelectedIndexChanged="rbgThreadStatus_SelectedIndexChanged" onclick="return rdblst_onClick();" AutoPostBack="True">
  <asp:ListItem Selected="True" Value="0">Alpha</asp:ListItem>
  <asp:ListItem Value="1">Bravo</asp:ListItem>
  <asp:ListItem Value="2">Charlie</asp:ListItem>
  <asp:ListItem Value="3">Delta Tickets</asp:ListItem>
  <asp:ListItem Value="4">Echo</asp:ListItem>
  </asp:RadioButtonList> <input type="hidden" value="0" id="hdnValue" runat="server" />


Following is the Javascript

JavaScript
function rdblst_onClick()
{
    var hdnValue = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_hdnValue');
    var length = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus').cells.length;
    for (var i = 0; i < length; i++)
    {
        if (document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).checked)
        {
            if (hdnValue.value != document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).value)
            {
                hdnValue.value = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus_' + i.toString()).value;
                //Some code here
            }
        }
    }
}
Posted
Updated 25-Aug-11 19:32pm
v3

1 solution

There might be any error in javascript.
Its working fine at my end.

Try this code in a new page. Its working.
XML
<asp:RadioButtonList ID="rbgThreadStatus" runat="server" RepeatDirection="Horizontal"
            OnSelectedIndexChanged="rbgThreadStatus_SelectedIndexChanged" onclick="return rdblst_onClick();" />
        <asp:ListItem Selected="True" Value="0">Alpha</asp:ListItem>
        <asp:ListItem Value="1">Bravo</asp:ListItem>
        <asp:ListItem Value="2">Charlie</asp:ListItem>
        <asp:ListItem Value="3">Delta Tickets</asp:ListItem>
        <asp:ListItem Value="4">Echo</asp:ListItem>
        </asp:RadioButtonList>
        <input type="hidden" value="0" id="hdnValue" runat="server" />
        <script type="text/javascript">
            function rdblst_onClick() {
                alert('hello');
            }
        </script>
 
Share this answer
 
Comments
MathewPV 26-Aug-11 2:03am    
The above code I have posted works fine in IE but not in other browsers

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