Reputation: 1
I've a kendo dropdownlist which displays a primary location. I want the dropdown to set to this primary location as the default location when I click on reset.
I'm using this:
$("#dropDownList").val(20);
$("#dropDownList").trigger("change");
It's internally changing the value, but the display text does not change.
I tried the following options but nothing seems to be changing the default text:
$('#dropDownList option[Value=20]').attr('selected', 'selected');
$('select#dropDownList').val('20');
Upvotes: 0
Views: 1856
Reputation: 12295
For a kendoDropDownList
control, you need to do the following:
var data = [
{ text: "Black", value: "1" },
{ text: "Orange", value: "20" },
{ text: "Grey", value: "3" }
];
// create DropDownList from input HTML element
$("#dropDownList").kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
dataSource: data,
index: 0,
change: onChange
});
var dropDownList= $("#dropDownList").data("kendoDropDownList");
dropDownList.select(function(dataItem) {
return dataItem.value === "20"; //20 is selected now
});
dropDownList.trigger("change");
Upvotes: 1
Reputation: 4137
You basically want this then which sets the selected option to the value you want.
$('#dropDownList').on('change', function(){
$('#dropDownList option:selected').val('20');
});
Upvotes: 0