Question

I have a html autocomplete textbox,my problem is when i try and enter an address eg. "New York" and click on submit button.It does not retrieve the input value.(does not return any value)

Test.aspx

<!--Address-->
    <div class="form-group">
         <label class="col-sm-3 control-label no-padding-right">Address</label>
         <div class="col-sm-7">

            <input id="tb_address" type="text" class="form-control" placeholder="Type 'a' or 'h'" />

    </div>
</div>

My javascript code in Test.aspx page

<script type="text/javascript">
        jQuery(function ($) {


            //custom autocomplete (category selection)
            $.widget("custom.catcomplete", $.ui.autocomplete, {
                _renderMenu: function (ul, items) {
                    var that = this,
                    currentCategory = "";
                    $.each(items, function (index, item) {
                        if (item.category != currentCategory) {
                            ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
                            currentCategory = item.category;
                        }
                        that._renderItemData(ul, item);
                    });
                }
            });

            var data = [
               { label: "New York", category: "North" },
           { label: "Rochester", category: "North" },
           { label: "California", category: "North" },

            ];
            $("#tb_address").catcomplete({
                delay: 0,
                source: data
            });




        });
    </script>

protected void bn_Submit_Click(object sender, EventArgs e)
{
  string address = Request.Form["tb_address"];

   lb_msg.Text = address;
}
Was it helpful?

Solution

I see that your input does not have a name, adapt the input tag as follows and try again:

<input id="tb_address" name="tb_address" type="text" class="form-control" placeholder="Type 'a' or 'h'" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top