locked
Creating Dynamic Textboxes With Auto Complete RRS feed

  • Question

  • User-712926555 posted

    Hi,

    I am creating Dynamic textbox. I need to get auto complete. I am using cssclass AutoComplete

    for (int i = 1; i <= count; i++)
     {
       TextBox _txtPdtName = new TextBox();
       _txtPdtName.ID = "txtPdtNameRow" + i;
       _txtPdtName.Attributes.Add("ClientIDMode", "Static");
       _txtPdtName.Width = 150;
       _txtPdtName.CssClass = "AutoComplete";
     }

    How to get dynamic textbox value using cssclass.

    $(function () {
                $(".AutoComplete").autocomplete({
                    source: function (request, response) {
                        var name = $(".AutoComplete").val();       //How to get textbox value
                        $.ajax({
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            url: "Prodcut.aspx/GetAutoCompleteDataByName",
                            data: "{'name':'" + name + "'}",
                            dataType: "json",
                            success: function (data) {
                                response(data.d);
                            },
                            error: function (result) {
                                alert("Check Name");
                            }
                        });
                    }
            });

    Wednesday, June 1, 2016 10:29 AM

Answers

  • User-712926555 posted
    var show_id = this.element.attr("id");
    var name = $('[id$=' + show_id + ']').val();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 12:16 PM

All replies

  • User475983607 posted

    Try...

    var name = $(this).val()

    Wednesday, June 1, 2016 11:05 AM
  • User-712926555 posted
    var show_id = this.element.attr("id");
    var name = $('[id$=' + show_id + ']').val();

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, June 1, 2016 12:16 PM
  • User61956409 posted

    Hi Hisanth,

    Firstly, I’m glad to hear that you resolve the problem by yourself. And thanks for sharing your solution.

    Secondly, we could also get the value currently in the text input from term property of request object.

    source: function (request, response) {
        var name = request.term;
        //your code
    }
    

    Best Regards,

    Fei Han

    Thursday, June 2, 2016 2:05 AM