Reputation: 99
I am having a razor page where there is a Kendo AutoComplete control and on its change event I need to get two things:
because there will be cloning of these two controls.
Here is my Code:
function autocomplete_select(e) {
var dataItem = this.dataItem(e.item.index());
var txtbx = $(this).closest("input[type='text']");
alert("Name==" + txtbx.attr('name'));
alert("ID==" + txtbx.attr('id'));
var tmp = $(this).closest("div.mf_form_field").find("input[type='text']").attr('id');
alert(tmp);
}
@(Html.Kendo().AutoComplete()
.Name("ACDD")
.BindTo((IEnumerable<String>)strActionCodes)
.Events(e => e.Select("autocomplete_select")))
</div>
<div>@Html.Label("Action Value")</div>
<div>@Html.TextBox("Value",null, new { style = "width : 105px"})</div>
Here none of the alert returning the ID of the textbox and i am not able to get the Name/ID of the kendo autocomplete.
Upvotes: 0
Views: 1947
Reputation: 20203
The id of the autocomplete is retrieved like this:
function onChange(e){
alert(this.element.attr('id'))
}
The closest (which in your case is not closest but next - check jQuery documentation for the difference between these two) to the textbox could be retrieved like this.
function onChange(e){
alert(this.wrapper.next('input[type="text"]').attr('id'))
}
Upvotes: 2