Kriitika
Kriitika

Reputation: 99

Get the ID/Name of Html.TextBox in the jquery select event of kendo AutoComplete

I am having a razor page where there is a Kendo AutoComplete control and on its change event I need to get two things:

  1. Id of that Kendo Autocomplete Control
  2. The nearest Text Box Id

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

Answers (1)

Petur Subev
Petur Subev

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

Related Questions