Detect time taken to type into Autocomplete field and auto select if only one item found <p>Right, I've nearly found what I'm after but not quite.</p> <p>Given a simple jQUery call to Autocomplete</p> <pre><code> $(".autoItem").each(function () { var id = $(this).attr("id"); var itemNumber = id.replace('item', ''); $(this).autocomplete({ source: "jsonOut/products.aspx", minLength: 2, select: function (event, ui) { $('#price' + itemNumber).val(ui.item.price); $('#id' + itemNumber).val(ui.item.id); } }); }); </code></pre> <p>Which works lovely, I am now over complicating it as usual due to my application.</p> <p>This is for a web form for making sales in a shop. The text box can be populated by two methods:</p> <p>A) Simply typing as normal.<br> B) Scanning a code with a bar code scanner. </p> <p>In case A, everything's fine, autocomplete works exactly as autocomplete was intended.</p> <p>In case B though, I have two issues:</p> <ol> <li><p>I need to be able to detect that this entry is from a scanner, so that the code behind knows to search the barcode field of my database, not item titles. Clearly the browser's not gonna know that, so the only way I can think is to do it by time. The scanner will populate the field faster than anyone can type.</p></li> <li><p>Once a result has been generated by AutoComplete with a barcode, it will clearly only return one result, so in cases where only one result is returned, I want it to auto-select that result and run it's select function populating the other fields as required. </p></li> </ol> <p>(the bar code scanner has a TAB terminator, so after scanning it immediately blurs the text field an moves on to the next one)</p> <p>Would something like this be possible?</p> <p>If someone could help with issue in isolation, that'd be cool. I have looked at <a href="https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js" rel="nofollow">https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js</a> for point B, but couldn't get it to work.</p> <p>NOTE: If the worst comes to the worst, I could detect scanned entries by using <code>isNumeri</code>c in the code behind, BUT, some codes we scan are not numeric, clearly proper UPC codes are, but we have some items with barcodes generated from product SKUs, these might not be numeric.</p>