This is a migrated thread and some comments may be shown as answers.

OnClientSelectedIndexChanged issue

3 Answers 98 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 05 Jul 2012, 11:46 PM
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>

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 09 Jul 2012, 12:13 PM
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.
0
Matthew
Top achievements
Rank 1
answered on 09 Jul 2012, 03:55 PM
this works perfect in FF but in IE, it is stating that the forEach is not supported.
0
Nencho
Telerik team
answered on 10 Jul 2012, 10:16 AM
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.
Tags
ComboBox
Asked by
Matthew
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Matthew
Top achievements
Rank 1
Share this question
or