OnClientSelectedIndexChanged issue

4 posts, 0 answers
  1. Matthew
    Matthew avatar
    25 posts
    Member since:
    Aug 2011

    Posted 05 Jul 2012 Link to this post

    I have a webpage that I need to dynamically set 4 radcombobox onclientselectedindexchanged events to a javascript function, however when the combobox index is changed the event does not get fired, can someone help me please?

    here is the javascript:

    <script type=
    "text/javascript">
        var cbxCSI = new Array(4);
        var rcbCSI = new Array(4);
         function OnLoad() {
            var onLoadCSIs = ['<%=objBidder.BidderCSI1%>', '<%=objBidder.BidderCSI2%>', '<%=objBidder.BidderCSI3%>', '<%=objBidder.BidderCSI4%>'];
     
            var rbWITHOUT = document.getElementById("rbWITHOUT");
            var lblWithoutCSI = document.getElementById("lblWithoutCSI");
     
            cbxCSI[0] = document.getElementById("cbxCSI1");
            cbxCSI[1] = document.getElementById("cbxCSI2");
            cbxCSI[2] = document.getElementById("cbxCSI3");
            cbxCSI[3] = document.getElementById("cbxCSI4");
     
            rcbCSI[0] = $find("clsCSIDivision_rcbClassifier");
            rcbCSI[1] = $find("clsCSIDivision1_rcbClassifier");
            rcbCSI[2] = $find("clsCSIDivision2_rcbClassifier");
            rcbCSI[3] = $find("clsCSIDivision3_rcbClassifier");
     
            rcbCSI[0].onclientselectedindexchanged = 'OnClientSelectedIndexChanged';
            rcbCSI[1].onclientselectedindexchanged = 'OnClientSelectedIndexChanged';
            rcbCSI[2].onclientselectedindexchanged = 'OnClientSelectedIndexChanged';
            rcbCSI[3].onclientselectedindexchanged = 'OnClientSelectedIndexChanged';
     
            function CheckWithoutStatus() {
                var allCbxUnchecked = true;
                for (i = 0; i < cbxCSI.length; i++) {
                    if (cbxCSI[i].checked == true)
                        allCbxUnchecked = false;
                }
                if (allCbxUnchecked == true) {
                    lblWithoutCSI.disabled = "";
                    rbWITHOUT.checked = true;
                }
            }
     
            if (rbWITHOUT.checked == true) {
                for (i = 0; i < cbxCSI.length; i++) {
                    if (rcbCSI[i].get_selectedItem().get_value() != "") {
                        rcbCSI[i].disabled = true;
                    }
                    else {
                        cbxCSI[i].disabled = true;
                    }
                    cbxCSI[i].checked = false;
                }
            }
            else {
                for (i = 0; i < cbxCSI.length; i++) {
                    if (rcbCSI[i].get_selectedItem.get_value() != "") {
                        rcbCSI[i].disabled = !cbxCSI[i].checked;
                    }
                    else {
                        cbxCSI[i].disabled = true;
                    }
                }
                CheckWithoutStatus();
            }
        }
        function OnClientSelectedIndexChanged(sender, eventArgs) {
            RefreshCsiOptions(sender);
        }
        function RefreshCsiOptions(sender) {
            switch (sender.type) {
                case "radio":
                    if (sender.checked == true) {
                        for (i = 0; i < cbxCSI.length; i++) {
                            if (rcbCSI[i].get_selectedItem().get_value() != "") {
                                rcbCSI[i].disabled = true;
                            }
                            else {
                                cbxCSI[i].disabled = true;
                            }
                            cbxCSI[i].checked = false;
                        }
                        lblWithoutCSI.disabled = "";
                    }
                case "checkbox":
                    var cbxNumber = sender.id.substr(6, 1);
                    if (sender.checked == true) {
                        rcbCSI[cbxNumber - 1].disabled = false
                        lblWithoutCSI.disabled = "disabled";
                        rbWITHOUT.checked = false;
                    }
                    else {
                        rcbCSI[cbxNumber - 1].disabled = true;
                    }
                    CheckWithoutStatus();
                case "select-one":
                    var rcbNumber = sender.id.substr(14, 1);
                    if (rcbNumber == "_")
                        rcbNumber = "0";
                    var rcbValue = rcbCSI[rcbNumber].get_selectedItem().get_value();
                    var radcb = $find('CSI' + rcbNumber + '_value');
                    var item = radcb.findItemByText(rcbValue);
                    if (item)
                    {item.select();}
                    if (rcbValue != "") {
                        cbxCSI[rcbNumber].disabled = false;
                        cbxCSI[rcbNumber].checked = true;
                        if (rbWITHOUT.checked == true)
                            rbWITHOUT.checked = false;
                    }
                    else {
                        cbxCSI[rcbNumber].disabled = true;
                        cbxCSI[rcbNumber].checked = false;
                        CheckWithoutStatus();
                    }
                default:
                    //alert(sender.type);
                    break;
            }
        }   
    </script>
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 09 Jul 2012 Link to this post

    Hello Matthew,

    I've already answered your another support ticket regarding the same issue.

    Please consider the following approach, which can be evolved in a manner to achieve a desired functionality :
    <script type="text/javascript">
      
           function pageLoad() {
      
               Telerik.Web.UI.RadComboBox.ComboBoxes.forEach(function myfunction(e) {
                   e.add_selectedIndexChanged(OnClientSelectedIndexChanged);
               })
           }
            
      
           function OnClientSelectedIndexChanged(sender, args) {
               alert("EventReached");
           }
      
       </script>



    Greetings,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matthew
    Matthew avatar
    25 posts
    Member since:
    Aug 2011

    Posted 09 Jul 2012 Link to this post

    this works perfect in FF but in IE, it is stating that the forEach is not supported.
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 10 Jul 2012 Link to this post

    Hi Matthew,

    Please consider the following approach in order to achieve the desired functionality in different browsers:

     
    <script type="text/javascript">
     
           function pageLoad() {
     
               for (i = 0; i < 5; i++) {
                   Telerik.Web.UI.RadComboBox.ComboBoxes[i].add_selectedIndexChanged(OnClientSelectedIndexChanged);
               }
           }
     
           function OnClientSelectedIndexChanged(sender, args) {
               alert("EventReached");
           }
      
       </script>

    Hope this information helps.

    Greetings,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top