You must Sign In to post a response.
  • Category: JavaScript

    How to add autocomplete textbox id

    hi all i have aform with textbox with autocompletesearch on enter of 3 character textbox is populated based on firstname value and lastname value will be filled
    so
    below is my code instead of +1 i need to pass autocomplete textbox suppose textbox id is aaa1
    i want to pass only 1 in below 1

    $("#FirstName" +1).val(json.licenses[0].code);
    $("#LastName" +1).val(json.licenses[0].desc);

    $.ajax({
    url: '/LocumTenens/populatefnamelname/',
    data: "{ 'licenseNumber': '" + i.item.val + "'}",
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    success: function (data) {
    var json = JSON.parse(data);
    $("#FirstName" +1).val(json.licenses[0].code);
    $("#LastName" +1).val(json.licenses[0].desc);

    counter++;
    },
    error: function (response) {
    //alert(response.responseText);
    },
    failure: function (response) {
    //alert(response.responseText);
    }

    });
    },
    minLength: 3

    });

    }
  • #769742
    As per my understanding you want to pass autocomplete textbox object instead of putting "+1" while assigning the response from JSON. if this is correct then you can directly use the control id like as below

    $(function () {
    $('#<%=txtcontrol.ClientID%>').autocomplete({
    source: function (request, response) {
    .ajax({
    url: '/LocumTenens/populatefnamelname/',
    data: "{ 'licenseNumber': '" +request.item.val + "'}",
    dataType: "json",
    type: "POST",
    contentType: "application/json; charset=utf-8",
    success: function (data) {
    var json = JSON.parse(data);
    $("#" + txtFirstNameId).val(json.licenses[0].code);
    $("#"+ txtLastNameId).val(json.licenses[0].desc);

    counter++;
    },
    }))

    hope it helps if not provide more information that what you are expecting.

    Thanks!
    B.Ramana Reddy


  • Sign In to post your comments