Note that there are some explanatory texts on larger screens.

plurals
  1. POTrigger event once dropdown item is selected on jQuery combobox
    primarykey
    data
    text
    <p>I'm using the autocomplete combobox from the jQuery UI library to create a couple text fields that also accept dropdowns -- basically a hybrid text/dropdown input. I customized it though so it also accepts free text input, not just items in the dropdown array. </p> <p>When the user selects an item from the dropdown, I'd like to trigger a function that populates the rest of the form based on the input. I don't want this function to trigger when the user types in a value manually. I'm not sure though how to bind an event specifically to the user selecting an item from the dropdown. </p> <p>Here's a Fiddle: <a href="http://jsfiddle.net/AhDHk/" rel="nofollow">http://jsfiddle.net/AhDHk/</a></p> <p>HTML: </p> <pre><code> &lt;input type="text" name="realtor-name" id="lp-realtor-name" value="" class="text ui-widget-content ui-corner-all" /&gt; </code></pre> <p>JS:</p> <pre><code>// adds the dropdown, dropArray is the list of items for the dropdown, id is the ID of the html input. function textDropdown(dropArray, id) { var $input = $(id).autocomplete({ source: dropArray, // this is an array fetched with AJAX of all the items for the dropdown minLength: 0 }).addClass("ui-widget ui-widget-content ui-corner-left"); $("&lt;button type='button'&gt;&amp;nbsp;&lt;/button&gt;") .attr("tabIndex", -1) .attr("title", "Show All Items") .insertAfter($input) .button({ icons: { primary: "ui-icon-triangle-1-s" }, text: false }) .removeClass("ui-corner-all") .addClass("ui-corner-right ui-button-icon lp-drop-button") .click(function() { // close if already visible if ($input.autocomplete("widget").is(":visible")) { $input.autocomplete( "close" ); return; } $(this).blur(); $input.autocomplete("search", "" ); $input.focus(); }); $("form").submit(function(e) { event.preventDefault ? event.preventDefault() : event.returnValue = false; alert($(this).serialize()); }); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload