How to programmatically select the first item in a jQuery Selectable list
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3140017/jquery-ui-how-to-programatically-select-selectables">jQuery-ui: How to programatically select selectables</a>  </p>
</blockquote>



<p>Having a bit of a time trying to get this to work. </p>

<p>How do I select the first(or for that matter any) item in a selectable list? Ideally, I'd like  the event 'stop' to fire in response to it as I have logic that sets values in other controls.  </p>

<p>Thank you,
Stephen</p>

<pre><code>$("#favoriteFolderSelectCopy").selectable({
    create: function () {
         // select the first item in the list??

    },
    stop: function () {

        var ar = $(".ui-selected", this);

        if (typeof (ar) === 'undefined') {
            return false;
        }

        if (ar.length === 1) {

            var folderName = $('.ui-selected', this).html();
            var ownerName = $('.ui-selected', this).attr('data-owner');
            var glCode = $('.ui-selected', this).attr('data-glcode');

            $("#favMaintName").val(folderName).removeClass("defaultTextActive").focus();
            $("#favMaintOwner").val(ownerName);
            $(".ui-autocomplete-input").val(glCode);

            return true;
        }


        if (ar.length &gt; 1) {

            //$("#favMaintName").val(ar[0]["data-id"]);
            return true;
        }

    }

});
</code></pre>

<p><a href="http://jqueryui.com/demos/selectable/#serialize" rel="nofollow">http://jqueryui.com/demos/selectable/#serialize</a></p>

<pre><code>&lt;ul class="ui-selectable" id="favoriteFolderSelectCopy"&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976199074" class="ui-widget-content ui-selectee ui-selected"&gt; &lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2977088462" class="ui-widget-content ui-selectee"&gt;ATLAS TEST Share&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976171424" class="ui-widget-content ui-selectee"&gt;Food-Canned Goods&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976199547" class="ui-widget-content ui-selectee"&gt;Food-Frozen&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976199546" class="ui-widget-content ui-selectee"&gt;Food-Meat&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2977213083" class="ui-widget-content ui-selectee"&gt;HDS CANADA&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2977213137" class="ui-widget-content ui-selectee"&gt;HDS CANADA2&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976539509" class="ui-widget-content ui-selectee"&gt;Kirsten Test&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976380310" class="ui-widget-content ui-selectee"&gt;Light Bulbs&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976377957" class="ui-widget-content ui-selectee"&gt;Office Supplies&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2003130884" class="ui-widget-content ui-selectee"&gt;Rooms - Appliances&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="1776652731" class="ui-widget-content ui-selectee"&gt;Rooms - Chemicals&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="1752600210" class="ui-widget-content ui-selectee"&gt;Rooms - Guest Supplies&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2165588708" class="ui-widget-content ui-selectee"&gt;Rooms - In-Room Coffee&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="1771586932" class="ui-widget-content ui-selectee"&gt;Rooms - Linens&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2003130835" class="ui-widget-content ui-selectee"&gt;Rooms - Uniforms&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2977213478" class="ui-widget-content ui-selectee"&gt;SYSCO punchout test&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976380420" class="ui-widget-content ui-selectee"&gt;Steve's Stuff&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976377950" class="ui-widget-content ui-selectee"&gt;USFI&lt;/li&gt;
    &lt;li data-owner="" data-glcode="" data-id="2976490556" class="ui-widget-content ui-selectee"&gt;walk IN #1&lt;/li&gt;
&lt;/ul&gt; 
</code></pre>
