select2 - submit form on select
<p>that might be a simple question, but I am not yet so firm with JavaScript.</p>

<p>I want to have a search form with autocomplete using select2.</p>

<p>When the user selects a result in the select2 dropdown box, I want to submit the search form right away so that I do not need a button for the form.</p>

<p>I found the select2:select event handler - but I do not get it to work. Any help?</p>

<p>My select2 works fine and if I include a button, I can submit the form and receive the selected object id:</p>

<pre><code>&lt;form action="" method="get" id="project-search"&gt;
        &lt;select class="form-control"
                data-autocomplete-light-function="select2"
                data-autocomplete-light-url="/output/project-autocomplete/"
                data-placeholder="Suche nach Projektnr. oder Projektleiter"
                id="id_projekt" name="projekt"&gt;
            &lt;option value="" selected="selected"&gt;----------&lt;/option&gt;
        &lt;/select&gt;
&lt;/form&gt;
</code></pre>

<p>That javascript snippet does not seem to work:</p>

<pre><code>&lt;script type="text/javascript"&gt;
    $(document).ready(function() {
    $eventSelect.on("select2:select", function() {
       console.log("select2:select");
       $(this).parents('form').submit();
    });
});
&lt;/script&gt;
</code></pre>

<p>Edit: I get this error message in my chrome console:</p>

<pre><code>Uncaught ReferenceError: $eventSelect is not defined
</code></pre>

<p>Thank you!</p>

<p>I am using django with django-autocomplete-light for the backend btw.</p>