Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1445
Another Javascript Question???
posted

When I set the selected item in the drop down I do this.....

this

 

.ddlMeasurementType.SelectedItemIndex = 2;

Without click on the control and I ran the following java I do not get index 2 as selected...

This basically gets ran when the text in a textbox is changed. The function is called ok but item.isSelected comes back as false for itemIndex 2 in the drop down. Is there something I am missing when setting selected item?  When I look at the drop down items in the server code it does have that item as selected = true; So I am don't know what I am missing on the client side. It looks like I might have to activate the item. Does anyone know how to do that?  I tried .ActiveItemIndex and that does not help. When I go into .Iem.Activated it is still false. When the .isSelected works in the javascript .Activate = true. I don't know I how to make this work.

 

var ddl2 = $find('<%= ddlMeasurementType.ClientID %>');

 

var items = ddl2.get_items();

 

var length = items.getLength();

 

var item;

 

for (var i = 0; i < length; i++) {

item = items.getItem(i);

 

if (item.isSelected()) {

SetCalculationLabels(item._element.innerText);

 

break;

}

 

  • 49378
    Suggested Answer
    posted

    Hi apalcer,

    From javascript you can select an item in the WebDropDown using the selectItem() or selectItemByIndex() functions.

    I am attaching a sample which changes the selected item in a drop down based on which of the buttons on the page is clicked.

    Below is the javascript code used:


        <script type="text/javascript">
            function Button1Handler() {
                $find('WebDropDown1').selectItemByIndex(0);
                return false;

            }
            function Button2Handler() {
                $find('WebDropDown1').selectItemByIndex(1);
                return false;

            }
       
        </script>

    Please tell me if this helps.

    Best Regards,

    Petar Ivanov
    Developer Support Engineer
    Infragistics, Inc.
    http://es.infragistics.com/support

    WebDropDownSelectItemClientSide.zip