0

This jquery function works great for me as a dropdown list that fills the input box upon selection.

my problem is that I want to use an ASP.net textbox rather than the input box.(mainly to refer to it when I click the "submit" button) when I exchange the two my dropdown function no longer works.

Thanks for the help

<html>
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Scrollable results</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <style>
  .ui-autocomplete {
    max-height: 400px;
    overflow-y: auto;
    /* prevent horizontal scrollbar */
    overflow-x: hidden;
  }

  /* IE 6 doesn't support max-height

   * we use height instead, but this forces the menu to always be this tall

   */

  * html .ui-autocomplete {
    height: 400px;
  }
  </style>
  <script>
      $(function () {
          var availableTags = [

"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
    ];
          $("#tags").autocomplete({
              source: availableTags
          });
      });
  </script>
</head>
<body>

<div class="ui-widget">

  <label for="tags">Select a procedure: </label>

    <input id="tags" type="text" />
    <asp:Button ID="Button1" runat="server" Text="Submit" />

</div>
</body>
</html>
1
  • How are you setting the id of the ASP:TextBox? You need to use ClientID, not id. Commented Sep 25, 2014 at 22:34

2 Answers 2

2

Either use:

<asp:TextBox id="tags" ClientIDMode="static" runat="server" />

Which will generate the clientID to be the same as the id you have set, or

<asp:TextBox id="tags" runat="server" />

and use the jquery selector like

$("#<%= tags.ClientID %>").autocomplete({......
Sign up to request clarification or add additional context in comments.

3 Comments

It should be $("#" + <%= tags.ClientID %>") instead... you have to add the extra "#" when selecting by ID
Good catch Keyvan. Updated my response.
thank you for your help sirs. sorry I took so long to accept this
0

If id is the problem then try assigning a dummy class for the textbox and reference the control using the class name. Upon Submit button click you will be able to access the tags textbox server control.

<asp:TextBox id="tags" runat="server" class ="txtauto" />

Then in your JS

$(".txtauto").autocomplete({
       source: availableTags
});

1 Comment

Class is best suited for a class of elements instead of one single element. It's best to use the ClientID for this purpose.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.