开发者

Radio button list on click function not working in Mozilla and Chrome

开发者 https://www.devze.com 2023-03-30 17:37 出处:网络
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:

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:

<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:

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.v开发者_开发知识库alue != 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
            }                      
        }
    }
}


Here is a Javascript change. It works in all browsers.

function GetFormObject(objname) {
        var obj;
        for (i = 0; i < document.forms[0].length; i++) {
            obj = document.forms[0].elements[i];
            if (obj.id.indexOf(objname) != -1) {
                break;
            }
        }
        return obj;
    }

    function rdblst_onClick() {
        var hdnValue = GetFormObject('hdnValue'); 
        var length = GetFormObject('rbgThreadStatus').parentNode.parentNode.cells.length;

        for (var i = 0; i < length; i++) {
            if (GetFormObject('rbgThreadStatus_' + i.toString()).checked) {
                if (hdnValue.value != GetFormObject('rbgThreadStatus_' + i.toString()).value) {
                    hdnValue.value = GetFormObject('rbgThreadStatus_' + i.toString()).value;
                    //Some code here
                }
            }
        }
    }


Found the solution

var length = document.getElementById('ctl00_ctl00_MainMaster_ContentPlaceHolder2_rbgThreadStatus').rows[0].cells.length;
0

精彩评论

暂无评论...
验证码 换一张
取 消