Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID attribute from Kendo dropdownList change event

I am using the kendo dropdownlisthelper, which has a change event, see below

@(Html.Kendo().DropDownListFor(m => m)
        .Name(Model.Name)
        .Text(Model.PlaceHolder)
        .BindTo(Model.ListItems)
        .DataTextField("Text")
        .DataValueField("Value")
        .Enable(Model.Enabled)
        .Events(e =>
        {
            e.Change("change");
        })
        .HtmlAttributes(new {@id= Model.ID.ToString() })

The function that handles the change event:

function change(e) {
    var dataItem = this.dataItem(e.item);
    console.log("selected values (" + dataItem.Text + " : " + dataItem.Value + ")");
}

SO this displays the selected value in the console.

The Question: I'm struggling to work this out, but how do i display the Name and ID of the parent element that made the call to the change event(in this case the drop-down list).

So basically i want to display these values: - Name attribute of the dropdown list - Id attribute of the dropdown list

Cheers!

like image 636
MCSD Avatar asked Jan 05 '23 13:01

MCSD


1 Answers

You can use this approach to get Id of element on which event have occured

function change(e) {
    var elementId = e.sender.element[0].id
}
like image 96
Anton Avatar answered Jan 08 '23 03:01

Anton