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

Cannot select DropDownList item in javascript

2 Answers 219 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 28 Jul 2015, 10:48 AM

Hi, I am using Kendo for ASP.Net MVC version 2015.2.264

I am trying to set the selected value of a dropdown list programatically via javascript as follows, but it always returns null:

        var ddl = $("#selDFTAlignment").data("kendoDropDownList");
        if (ddl == null) { alert('null ddl'); return; }
        ddl.select("1");​

 

I use the MVC wrappers to define the dropdown which generates the dropdown script as follows:

jQuery(function(){jQuery("#selDTFAlignment").kendoDropDownList({"dataSource":[{"Text":"Left","Value":"0"},{"Text":"Centre","Value":"1"},{"Text":"Right","Value":"2"}],"dataTextField":"Text","template":"\u003cspan\u003e#:data.Text#\u003c/span\u003e","valueTemplate":"\u003cspan\u003e#:data.Text#\u003c/span\u003e","dataValueField":"Value"});});

 

The dropdown list is inside a div container for a modal popup:

<div id="mdlDefaultText" class="modal fade" role="dialog">​

 

Why is the selector not working?  Am I missing something?  

2 Answers, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 28 Jul 2015, 01:34 PM
I have tested the same code against a kendo dropdownlist defined directly using Kendo UI javascript rather than via the MVC wrapper, and the selector works perfectly against this dropdownlist, so the issue is with the MVC wrapper generated code.
0
David
Top achievements
Rank 1
answered on 28 Jul 2015, 03:04 PM
AArgghhhh ..... please ignore this - it was a typo on my part - I had transposed two letters in the dropdownlist name.
Tags
General Discussions
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or