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

listBox.get_items().get_count()... Object does not support this property or method.

2 Answers 149 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Mych
Top achievements
Rank 1
Mych asked on 13 Feb 2014, 04:34 PM

I have the following bit of code that I have taken from Telerik examples... I have a Rad Window with two RadListBoxes. When the user clicks a button the function returnToParent() is called. This should
a) find the RadListBox2 (which it does)
b) find out how many items are in the RadListBox (this fails with the error Object does not support this property or method)
c) if there are no items show error message (yet to check)
d) iterate through each item and create a string containing each item separated with a semicolon and space (yet to check)
e) remove the last semicolon and space (yet to check)
f) close window id string has a value else give error message (yet to check)

This is my code.... why do I get the error Object does not support this property or method​ at line var x = listBox.get_items().get_count();

<script type="text/javascript">
  
        function GetRadWindow() {
            var oWindow = null;
            if (window.radWindow) oWindow = window.radWindow;
            else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
            return oWindow;
        }
  
        function returnToParent() {
            //create the argument that will be returned to the parent page
            var oArg = new Object();
  
            //get the ServiceNames name
            var listBox = document.getElementById("RadListBox2");
            listBox = $telerik.toListBox(listBox);
            //error at the next line...
var x = listBox.get_items().get_count(); 
            if (x < 1) {
                alert("The listBox is empty.");
                oArg.Services = "";
            }
            else {
                for (i = 0; i < x; i++) {
                    oArg.Services += listBox.get_items().get_item(i).value() + "; "
                }
                //remove the last semicolon and space
                oArg.Services = oArg.Services.substring(0, oArg.Services.length - 2);
            }         
             
            //get a reference to the current RadWindow
            var oWnd = GetRadWindow();
  
            //Close the RadWindow and send the argument to the parent page
            if (oArg.Service) {
                oWnd.close(oArg);
            }
            else {
                alert("At least one service must be assigned. If Unknown enter TBC.");
            }
        }
  
    </script>

Any help appreciated

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Feb 2014, 06:26 AM
Hi Mych,

Please try the following JavaScript which works fine at my end.

JavaScript:
var listBox = $find("<%=RadListBox2.ClientID %>");
var x = listBox.get_items().get_count();

Hope this will helps you.
Thanks,
Shinu.
0
Mych
Top achievements
Rank 1
answered on 17 Feb 2014, 10:50 AM
Thanks... This worked fine.
Tags
ListBox
Asked by
Mych
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Mych
Top achievements
Rank 1
Share this question
or