Articles in this section
Category / Section

Why the getSelectedValue method always returns the value in string, even the value in some other data type? Is there any way to achieve that?

1 min read


By default, getSelectedValue method is used to retrieve the items value that are selected in the DropDownList. It returns the item value in the “string” data type instead of corresponding data type of the item.



But, using itemValue property, we can get the selected items as it is. But the “itemValue” property is only applicable for Single Selection mode in the DropDownList.


In the following example, upon selecting the items in the DropDownList, the change event will be triggered. In the change event, itemValue will returns the selected value in the DropDownList and the returned value will be in its corresponding data type.


For reference, we have added the local method called “toType” which receives the selected value from the DropDownList and returns the data type of the value.


Please refer the following code snippet.


<input type="text" id="bikeList" />
    <script type="text/javascript">
        var target;
        $(function () {
            BikeList = [
                 { value: 2, text: "CBR 150-R" },
                 { value: "hello", text: "CBZ Xtreme" },
                 { value: 4, text: "Discover" },
                 { value: 5, text: "Dazzler" },
                 { value: 6, text: "Flame" },
                 { value: "hi", text: "Fazzer" },
                 { value: 8, text: "FZ-S" },
                 { value: 9, text: "Pulsar" },
                 { value: 10, text: "Shine" },
                 { value: 11, text: "R15" },
                 { value: 12, text: "Unicorn" }
            var ddl = $('#bikeList').ejDropDownList({
                dataSource: BikeList,
                change: function (args) {
                    var rteValue = args.model.itemValue;
                    alert("Type :" + toType(rteValue) + "      Value :" + (rteValue));
                    alert("Selected value :" + ddl.getSelectedValue());
        var toType = function (obj) {
            return ({})\s([a-zA-Z]+)/)[1].toLowerCase()



Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment