Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:24:44+00:00 2026-05-28T14:24:44+00:00

I’ve been at this for 12+ exhausting hours trying get it to work on

  • 0

I’ve been at this for 12+ exhausting hours trying get it to work on my page. Below I will include my codebehind (list source & getter), my jQuery (in the header wrapped in the “ready” function), and my asp.net dropdownlist control, button, and input objects wrapped in a div.
Here is the combobox I’m trying to implement. Nothing I have found yet has helped. It seems it’s an issue with linking actions and values together. Namely, the button does not toggle the dropdownlist to expand.

To make it easier, I’ve made all caps comments in the codeboxes to point out specifically where I need help. There are only two things left to troubleshoot. Thanks maties :-)>

Now onto the codebehind — (NOT THE MAIN ISSUE)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    combobox.DataSource = car_list
    combobox.DataBind()
End Sub

Protected car_list As New ArrayList({
                                         "Audi",
                                         "Lexus",
                                         "BMW",
                                         "Ford",
                                         "Chevrolet",
                                         "Jeep",
                                         "Jaguar",
                                         "Toyota",
                                         "Nissan",
                                         "Honda",
                                         "Subaru",
                                         "Hyundai",
                                         "Tesla",
                                         "Mercedez",
                                         "Ferrari"
                                         })

//'This function returns the above list as either a String list, or wrapped in a tag
Function getList(ByVal listName As ArrayList, Optional ByVal tagWrapper As String = "", Optional ByVal tagId As String = "") As String
    Dim items As String = "No items in list."
    If Not tagWrapper = "" Then  //'Return as HTML Tagged Objects, a.k.a. Elements or DOM Objects or Nodes
        For Each item In listName
            If Not tagId = "" Then
                items = "<" + tagWrapper + " id=""" + tagId + """" + ">" //'Used if "id" parameter passed in
                items += item.ToString
                items += "</" + tagWrapper + ">" & vbCrLf
            Else
                items = "<" + tagWrapper + ">"
                items += item.ToString
                items += "</" + tagWrapper + ">" & vbCrLf
            End If
        Next
    Else //'Return as String Array, e.g. ["item1", "item2", "item3"]
        For Each item In listName
            Dim isFirstItem As Boolean = True
            If isFirstItem Then //'Treat the first item differently
                isFirstItem = Not isFirstItem
                items = item.ToString
            Else
                items += ", " + item.ToString
            End If
        Next
    End If

    Return items
End Function

The jQuery (again, in the header) – (HERE BE DRAGONS!)

$(document).ready(function () {
    $("#autocomplete").autocomplete({
        delay: 0,
        minLength: 0,
        autoFocus: true,
        //This "source:" function is pulled from the jQuery Combobox link above.
        source: function (request, response) {
            var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
            response($("#combobox").children("option").map(function () {
                var text = $(this).text();
                if (this.value && (!request.term || matcher.test(text)))
                    return {
                        label: text.replace(
            new RegExp(
                "(?![^&;]+;)(?!<[^<>]*)(" +
                $.ui.autocomplete.escapeRegex(request.term) +
                ")(?![^<>]*>)(?![^&;]+;)", "gi"
//SOMETHING WRONG WITH THE REGEX REPLACE... THE "strong" TAGS ARE COMING THROUGH IN THE DROPDOWN :p
            ), "<strong>$1</strong>"),
                        value: text,
                        option: this
                    };
            }));
        } //END "source:"
        }); //END ".autocomplete"

    $("#combobox").combobox();
//THIS IS WHERE IT'S AT!!
//THE DROPDOWNLIST CONTROL SHOULD BE HIDDEN, BUT THIS BUTTON SHOULD TOGGLE ITS CONTENTS INTO VIEW
//Here is the code used in the "combobox" demo provided on the jQuery UI site, but for some reason
//  it doesn't work with mine. The key difference to note is that they created all their DOM
//  elements and attached the listeners etc. using the "(function ($) { });" form.
    $("#toggle").click(function () {
        // close if already visible
        if (input.autocomplete("widget").is(":visible")) {
            input.autocomplete("close");
            return;
        }

        // work around a bug (likely same cause as #5265)
        $(this).blur();

        // pass empty string as value to search for, displaying all results
        input.autocomplete("search", "");
        input.focus();
    });
});

And finally the markup (using the id as the handle)

<form action="#" method="post">
    <h2>Choose your favorite car</h2>
    <hr />
    <div class="ui-widget"> <!-- Autocomplete Combobox -->
        <asp:DropDownList ID="combobox" runat="server" ClientIDMode="Static"></asp:DropDownList><br />
        <input id="autocomplete" class="ui-autocomplete-input ui-widget ui-widget-content ui-corner-left" style="margin-right:0;" />
        <button id="toggle" type="button" tabindex="-1" title="Show All Items" class="ui-button ui-widget ui-state-default ui-button-icon-only ui-corner-right ui-button-icon" role="button" aria-disabled="false" style="margin:0 0 0 -7px;">
            <span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span><span class="ui-button-text" style="padding:0;">&nbsp;</span>
        </button>
    </div>
</form>

To make it a little more clear, both the button and input objects inside of the combobox ui-widget div should link to the asp.net control. I’m not hard set on the control, but I’ve tried it both ways and have been unsuccessful.

EDIT: WOOHOOOO!! I made the following change and got the datasource working. Now I just have to fix the button to make it toggle the view of the dropdownlist.

//In the jQuery "source" section I replaced
response(select.children("option").map(function ()
//with
response($("#combobox").children("option").map(function ()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:24:45+00:00Added an answer on May 28, 2026 at 2:24 pm

    Here’s my solution which I resolved a few months ago and just now have time to post it. In the future I hope to revise this Javascript to support option groups 🙂

    Basically I shoved all my JS off into a separate file and called my custom function passing in the DropDownList and TextBox for each respective Combobox I wanted to create. The DataSourceID was supplied to the DropDownList using an SqlDataSource to populate it from my database. ASP.NET renders this as a <select> element with an <option> element for each ListItem in the DropDownList. The jQuery UI autocomplete plugin reads these <option> elements and creates a hidden <ul> with a <li> for each corresponding <option> in the <select> element. The items are found by the line response($(ddl).children("option").map(function () {.... Note that replacing ‘children’ with ‘find’ will return options inside of an <optgroup> tag as well.

    Following is my markup which calls the JS function, followed by the JS function itself:

    <!-- Head section -->
    <script type="text/javascript">
        function pageLoad() {
            cbsetup("#TextBoxID", "#DropDownBoxID");
        });
    </script>
    
    <!-- Body section - SAMPLE COMBOBOX -->
    <span>
        <asp:DropDownList ID="DropDownBoxID" runat="server" DataSourceID="SDS"
            DataTextField="Name" DataValueField="ID"></asp:DropDownList>
        <asp:TextBox ID="TextBoxID" runat="server" CssClass="combobox
            ui-autocomplete-input ui-widget ui-widget-content ui-corner-left"></asp:TextBox>
        <!-- I know the button code is particularly nasty, no thanks to jQuery UI.
            I just copy/pasted for the most part -->
        <button id="ButtonID" type="button" tabindex="-1" title="Show All Items"
            class="toggle ui-button ui-widget ui-state-default ui-button-icon-only
            ui-corner-right ui-button-icon" role="button" aria-disabled="false"
            style="margin:0 0 0 -5px; height: 23px;">
            <span class="ui-button-icon-primary ui-icon ui-icon-triangle-1-s"></span>
            <span class="ui-button-text" style="padding:0;">&nbsp;</span>
        </button>
    </span>
    
    function cbsetup(cb, ddl) {
        try {
            $(cb).unbind();
            $(cb).autocomplete({
                delay: 300,
                minLength: 0,
                autoFocus: true,
                source: function (request, response) {
                    var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
                    response($(ddl).children("option").map(function () {
                        var text = $(this).text();
                        if (this.value && (!request.term || matcher.test(text)))
                            return {
                                label: text.replace(
                                    new RegExp(
                                        "(?![^&;]+;)(?!<[^<>]*)(" +
                                        $.ui.autocomplete.escapeRegex(request.term) +
                                        ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                    ), "$1" //"<style=\"text-weight:bold;\">$1</style>"
                                    ),
                                value: text,
                                option: this
                            };
                    }));
                },
                select: function (event, ui) {
                    ui.item.option.selected = true;
                },
                change: function (event, ui) {
                    if (!ui.item) {
                        var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
                                            valid = false;
                        select.children("option").each(function () {
                            if ($(this).text().match(matcher)) {
                                this.selected = valid = true;
                                return false;
                            }
                        });
                        if (!valid) {
                            // remove invalid value, as it didn't match anything
                            $(this).val("");
                            select.val("");
                            input.data("autocomplete").term = "";
                            return false;
                        }
                    }
                }
            });
    
            $(cb).siblings("button.toggle").click(function () {
                // close if already visible
                if ($(cb).autocomplete("widget").is(":visible")) {
                    $(cb).autocomplete("close");
                    return;
                }
    
                // work around a bug (likely same cause as #5265)
                $(this).blur();
    
                // pass empty string as value to search for, displaying all results
                $(cb).autocomplete("search", "");
                $(cb).focus();
            });
        } /* TRY END */
        catch (e) { jAlert(e.name + ', ' + e.message, 'JS Exception Caught'); }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.